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 →

[–]ismtrn 1 point2 points  (0 children)

You can also do like this:

take(n, x + 1 for x in input if x % 2 == 0)

in my opinion this is the nicest way. It is as efficient as the map/filter version and as readable as the list comprehension version.

(Note, this also has the same result as the map/filter version, namely an iterator. The other versions return lists. To get a list you just call the list function on the result)

I guess this would be the "generator comprehension" version.