1

I'm trying to learn more about the map() function and if I can use it to speed up iteration over massive lists in my other programs. Right now im trying to understand the output of the following code:

x = []
for y in range(1000):
    x.append(0)
print(x[0])

def func(y):
    global x
    x[y] += 1

for y in range(100):
    func(y)

print(x[0])

map(func, range(100))

print(x[0])

output:

0
1
1

Why is the output not

0
1
2

and what modifications would I need to make to the above code to achieve this output?

My interest is largely academic. Any information or direction to a good source is appreciated.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
asheets
  • 770
  • 1
  • 8
  • 28

0 Answers0