News for hackers. Stuff that matters.
Re:The Zen of Python by Example by drdaeman on Thursday February 10, 2011 @06:49PM (#2204441)
With [...] you are doing the same as list(...), so your example would return a list:

    >>> evens_only([1,2,3,4,5])
    [1, 2]
If you want a generator instead:

    evens_only = lambda nums: (n/2 for n in nums if n%2==0)
So you'll get:

    >>> evens_only([1,2,3,4,5])
    <generator object <genexpr> at 0x7f2ef79eaa00>
I don't know which one would be more Pythonic, clean and simple lambda one-liner or two-lined simple function.

There are no comments on this comment yet.