# Given the following three list, how would you create a new list that matches the desired output printed below?

Given the following three list, how would you create a new list that matches the desired output printed below?

fruits = [‘Apples’, ‘Oranges’, ‘Bananas’]
quantities = [5, 3, 4]
prices = [1.50, 2.25, 0.89]

#Desired output
[(‘Apples’, 5, 1.50),
(‘Oranges’, 3, 2.25),
(‘Bananas’, 4, 0.89)]

• output = []
fruit_tuple_0 = (first, quantities, price)
output.append(fruit_tuple)
fruit_tuple_1 = (first, quantities, price)
output.append(fruit_tuple)
fruit_tuple_2 = (first, quantities, price)
output.append(fruit_tuple)
return output
• i = 0
output = []
for fruit in fruits:
temp_qty = quantities[i]
temp_price = prices[i]
output.append((fruit, temp_qty, temp_price))
i += 1
return output
• groceries = zip(fruits, quantities, prices)
return groceries
>>> [
(‘Apples’, 5, 1.50),
(‘Oranges’, 3, 2.25),
(‘Bananas’, 4, 0.89)
]
• i = 0
output = []
for fruit in fruits:
for qty in quantities:
for price in prices:
output.append((fruit, qty, price))
i += 1
return output

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.