The following code does not print anything from the for
loop; it only prints the result of the tuple
. This is very unintuitive because I haven't explicitly modified the cheapest
map, yet it behaves as if it is empty after calling tuple
.
So, what's going on?
store1 = [10.00, 11.00, 12.34, 2.34]
store2 = [9.00, 11.10, 12.34, 2.01]
cheapest = map(min, store1, store2)
print(tuple(cheapest))
for v in cheapest:
print(v)
Expected output:
(9.0, 11.0, 12.34, 2.01)
9.0
11.0
12.34
2.01
Actual output:
(9.0, 11.0, 12.34, 2.01)
If I run the for
loop first, then the behavior is reversed: the for
loop prints the values from the cheapest
map and the print(tuple(cheapest))
result is empty as in:
Actual output (order reversed):
9.0
11.0
12.34
2.01
()