4 ms·
Python actually discourages using map anf filter. Which is kind of weird to me but whatever.
by pryelluw 9y ago
Python actually discourages using map anf filter. Which is kind of weird to me but whatever.
- nerdponx 9y agoWell in some cases it really is more efficient. [func(x) if x in collection if cond(x)] makes a single pass over the data and gives you a list, but list(map(func, filter(cond, collection))) makes two passes and requires some extra function calls. I think the real reason is perceived legibility on the part of the Python core devs. I seem to recall a document from a while ago in which GvR himself came out in favor of list comprehension style. "Explicit is better than implicit".
- nitroll 9y agoBoth map and filter returns an iterator, so you only iterate once when creating the list.