I am using list comprehension to create a dictionary. The Iterable is created using zip function on two individual lists. If print function is used to check the list of this zip object and then dictionary is being created, it produces an empty dictionary. Whereas if list of this zip element is not printed, then dictionary is created as expected. Please explain why this is happening.
drinks = ["espresso", "chai", "decaf", "drip"]
caffeine = [64, 40, 0, 120]
zipped_drinks = zip(drinks, caffeine)
print(list(zipped_drinks))
drinks_to_caffeine = {key:value for key,value in zipped_drinks}
print(drinks_to_caffeine)
This produces :- [('espresso', 64), ('chai', 40), ('decaf', 0), ('drip', 120)] {}
If "print(list(zipped_drinks))" is removed, output is :- {'espresso': 64, 'chai': 40, 'decaf': 0, 'drip': 120}