checking if a list is empty

Ian Kelly ian.g.kelly at gmail.com
Wed May 11 12:31:59 EDT 2011


On Wed, May 11, 2011 at 8:34 AM, Hans Georg Schaathun <hg at schaathun.net> wrote:
> E.g. Anyone who has used list/set comprehension in Z, haskell, set theory,
> or whereever will understand python list comprehension immediately.

They would understand the underlying concept.  But would somebody who
is not a Python programmer intuitively understand the difference
between this:

[x + 3 for x in xs if x % 2 == 1]

and this:

{x + 3 for x in xs if x % 2 == 1}

and this:

(x + 3 for x in xs if x % 2 == 1)

Somebody with rudimentary Python knowledge might even reason that
since the first two create a list and a set respectively, the third
must therefore create a tuple, which is wrong.

None of this should be taken as an argument against using generator expressions.



More information about the Python-list mailing list