Early Global Object Destruction in Functions?
So I was inspecting a Python code: x = input().split(',') y = map(int,input().split(',')) def n(): return sum(y) def m(): return sum(y)/len(x) print(n()) print(m()) with the input: a,b,c 1,2,3 I realized that for some reason, the second print which calls m() would always return 0.0. Surprisingly, removing the first print from the code will cause m() to properly return 2.0. Probing deeper, I found out that sum(y) in m() returned 0.0. The map object stored within y appears to have been destroyed after the first function call (n()). Replacing the map object with a list: y = list(map(int,input().split(','))) would fix the issue, but how is this possible? Thread which contains the original code which caught my attention: https://www.sololearn.com/Discuss/1347558/?ref=app