Alex Rivera | Logout

Is there a value in using map() vs for?

Asked 2009-05-17T19:45:43.520
10

Does map() iterate through the list like "for" would? Is there a value in using map vs for?

If so, right now my code looks like this:

for item in items:
    item.my_func()

If it makes sense, I would like to make it map(). Is that possible? What is an example like?

Edit
Report

1 Answer

0

Map can sometimes be faster for built-in functions than manually coding a for loop. Try timing map(str, range(1000000)) vs. a similar for loop.

answered 2009-05-18T22:02:03.713

Your Answer