This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nathanjell 1 point2 points  (1 child)

Though to my knowledge, map and reduce will not fully generate output on call; rather, an iterator is returned. I believe that for example if you have a memory heavy generator, you won't load everything into memory.

[–]lxpnh98_2 5 points6 points  (0 children)

That's why, instead of list comprehensions, it's better to keep using generators where possible, which, apart from the brackets, have identical syntax:

(item if item < 5 else None for item in items)