Python Practice › Dictionary Programs › Program 34
Letter combinations from values
Write a Python program to print every combination of one letter from each dictionary value.
Input
{"x": ["e", "f"], "y": ["a", "b"]}Output
ea eb fa fb
Approach
itertools.product(*d.values()).
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.