2
I want to take 2 lists and turn them into a dictionary, in which each item has as key the i-th item of the first list and as value the i-th item of the second list.
I made that code so far:
lista_de_compras = ['arroz', 'feijao', 'macarrao']
preco_dos_itens = ['2.00', '3.80', '4.90']
lista_nova = {}
for item in lista_de_compras:
for preco in preco_dos_itens:
lista_nova[item] = preco
print(lista_nova)
But when I printo this new listing (which in this case is the dictionary), it applies the items correctly in the keys, but I did not understand the pq it repeat in all only the last price of the item for all the items, and how to solve this problem:
output:
{''rice: '4.90', 'beans': '4.90', 'pasta': '4.90'}
A very good module that facilitates a lot, I at least did not know this function. Thank you so much for sharing.
– José Marinho