Letter combinations from values

EasyDictionary Programs · 34 of 94

Write a Python program to print every combination of one letter from each dictionary value.

Advertisement
Input
{"x": ["e", "f"], "y": ["a", "b"]}
Output
ea
eb
fa
fb

Approach

  1. itertools.product(*d.values()).

Solution

Python
from itertools import product d = {"x": ["e", "f"], "y": ["a", "b"]}for combo in product(*d.values()):    print("".join(combo))
Output
ea
eb
fa
fb
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs