[Python-Dev] List comprehensions

Tim Peters tim.one@comcast.net
Fri, 05 Jul 2002 13:48:11 -0400


[Alex Martelli]
> The real (and no doubt PSU-intended) use of list comprehensions is, of
> course, to finesse Python's _apparent_ lack of assignment-in-expression.
>
> Instead of coding a vulgar, typo-prone, hoi-polloi oriented:
>     while x = bluh():
>         whatever(x)
> you get to code an elegant, refined, hoi-oligoi reserved:
>     while [ x for x in [bluh()] if x ] :
>         whatever(x)

Excellent!  Guido uses

    while [x for x in [bluh()]][0]:
        whatever(x)

because he thinks it's "more elegant" (whatever that means to a Dutch guy),
but either way it's major relief from the obscurity of embedded assignment.

> (I'm told Beretta makes excellent small arms, should you need one...).

Thanks for the suggestion!  Some Americans consider it rude to shoot
coworkers, so I'm always looking for ways to get across to them that it's
more a matter of defending good taste than of killing people.  Using a piece
with sleek Italian design should go a long way toward helping to make this
point.