[Python-Dev] List comprehensions
Alex Martelli
aleax@aleax.it
Fri, 5 Jul 2002 08:08:16 +0200
On Thursday 27 June 2002 01:29, Tim Peters wrote:
> [Gerald S. Williams, on listcomp (non)scopes]
>
> > No problem. As long as it was decided that there's a use for
> > the current behavior, I won't question it.
>
> I'm not sure there's a use for it, but I am sure I'd shoot any coworker
> who found one and relied on it <wink>.
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)
(I'm told Beretta makes excellent small arms, should you need one...).
Alex