Yahia Naeem
Yahia Naeem

Reputation: 61

how to manipulate dictionary of lists?

How to complete the blanks to get the output:

red shirt
blue shirt 
white shirt
blue jeans
black jeans

Code:

wardrobe = {"shirt":["red","blue","white"], "jeans":["blue","black"]}
for __:
    for __:
        print("{} {}".format(__))

Upvotes: 0

Views: 123

Answers (2)

dspencer
dspencer

Reputation: 4471

wardrobe = {"shirt": ["red", "blue", "white"],
            "jeans": ["blue", "black"]}
for item, colors in wardrobe.items():
    for color in colors:
        print("{} {}".format(color, item))

Upvotes: 2

alec
alec

Reputation: 6112

for key in wardrobe:
    for color in wardrobe[key]:
        print("{} {}".format(color, key))

Upvotes: 2

Related Questions