In Python, a dictionary can only hold a single value for a given key. To work around this, our single value can be a list containing multiple values. Here we have a dictionary called "wardrobe" with clothing items and their colors. Fill in the blanks to print a line for each item of clothing with each color, for example: "red shirt", "blue shirt", and so on.
wardrobe = {"shirt":["red","blue","white"], "jeans":["blue","black"]}
for __:
for __:
print("{} {}".format(__))
my code
wardrobe = {"shirt":["red","blue","white"], "jeans":["blue","black"]}
for cloths in wardrobe.keys():
for colors in wardrobe.values():
print("{} {}".format(colors,cloths))
I want to print it like red shirt, blue shirt, white shirt...
In Python, a dictionary can only hold a single value for a given key. To workaround this, our single value can be a list containing multiple values. Here we have a dictionary called "wardrobe" with items of clothing and their colors. Fill in the blanks to print a line for each item of clothing with each color, for example: "red shirt", "blue shirt", and so on.
This gives the accurate required answer
wardrobe = {"shirt":["red","blue","white"], "jeans":["blue","black"]}
for clothes,colors in wardrobe.items():
for color in colors:
print("{} {}".format(color,clothes))
output
Here is your output:
red shirt
blue shirt
white shirt
blue jeans
black jeans
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With