3 ms·
I mentioned it in the article: map was going to be deprecated in 3000, but now will return iterators. Contextually, not what you want.
by avinashv 19y ago
I mentioned it in the article: map was going to be deprecated in 3000, but now will return iterators. Contextually, not what you want.
- etal 19y agoPy3K goes wild with generators. Basically, everything that used to return a list (e.g. range()) now returns an iterable, and to get a list you just apply the list() constructor to that. It's about lazy evaluation. So these will be equivalent: dinner = [eggs(x) for x in spam] dinner = list(eggs(x) for x in spam) dinner = list(map(eggs, spam) The real reason list comprehensions are favored over map() and filter() are that the latter two require another Python function call, while list comprehensions are evaluated directly by the interpreter (a bit like rewriting the loop in C or using Pyrex) -- better performance.