Python Dictionary and list confusion

Viewed 183

Hi I am trying to learn dicts and list in Python. My code:

wardrobe = {"shirt":["red","blue","white"], "jeans":["blue","black"]}
for clothes in wardrobe.values():
    for colors in wardrobe.keys():
        print("{}{}".format(clothes (colors) ))

My result should be "red shirt", "blue shirt", and so on... My error code is : TypeError: 'list' object is not callable

Kindly help with simple description

2 Answers

I think this is what you meant to do:

wardrobe = {"shirt":["red","blue","white"], "jeans":["blue","black"]}

for cloth, colors in wardrobe.items():
    for color in colors:
        print("{} {}".format(color, cloth))

I believe this is what you're trying to do:

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

Output:

red shirt
blue shirt
white shirt
blue jeans
black jeans
Related