I encountered a weird phenomena while playing around with python. The following two different codes give different outputs whereas, in my opinion, they (the codes) should be equivalent.
Snippet 1:
store1 = [10.00, 11.00, 12.34, 2.34]
store2 = [9.00, 11.10, 12.34, 2.01]
cheapest = list(map(min, store1, store2))
print(list(cheapest))
list(cheapest)
Snippet 2:
store1 = [10.00, 11.00, 12.34, 2.34]
store2 = [9.00, 11.10, 12.34, 2.01]
cheapest = (map(min, store1, store2))
print(list(cheapest))
list(cheapest) #shows empty list
Looking at the outputs from these two snippets (the only difference in declaration of cheapest
from line 3), I conclude that using list(x)
, where x
is a map, at any other point other than declaration of the variable, actually deletes/clears the contents of the map.
I can't figure out why this is happening (or if my inference is even correct), any help would be appreciated :)