map versus the 'for' loop

Ionel Simionescu ionel at psy.uva.nl
Sat Dec 4 09:11:16 EST 1999


Hi,


In some situations, the use of map() can speed up things, which would
normally be done in a loop.

--- e.g.

# <map>
y = map(func, x)

# vs.

# <for loop>
y = [None]* len(x)
for k in range(x): y[k] = func(x[k])

---

I hereby ask those with knowledge about the interpreter's internals what the
trade-offs/cavets are.

The speed gain brought by map() might have a cost (e.g. space) that I'm not
aware of, and which could bite in certain situations.


Thank you,
ionel






More information about the Python-list mailing list