here is the data. I want to unpack this tuple and print the message.
shopping_list = [("fruits",'apple','peach'),('dairy','cheese','milk')]
#Use for loop to iterate over list and get each tuple for unpacking
for item in shopping_list:
#unpack the tuple into item and section variables
item1 = fruits
item2 = dairy
#print the message
print("You can find the" "" "in the" fruits "section")
"Next, you want to use this list to print out where each item is available.
The message could be as follows:
"You can find the [item] in the [section] section""
How can I write this??
I provided the data above. Please help
CodePudding user response:
try this.
shopping_list = [("fruits",'apple','peach'),('dairy','cheese','milk')]
for item in shopping_list:
section = item[0]
item1 = item[1]
item2 = item[2]
print(f'You can find the "{item1}" "{item2}" in the " {section} "section')