Half-baked idea: list comprehensions with "while"

Chris Angelico rosuav at gmail.com
Fri Apr 27 07:38:26 EDT 2012


On Fri, Apr 27, 2012 at 8:37 PM, Tim Wintle <tim.wintle at teamrubber.com> wrote:
> Or like:
>
>>>> print [ 0 if b%2==1 else 1 for b in range(10)]
> [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]

That's nothing to do with the list comp, that's just the expression-if
syntax that you can use anywhere.

ChrisA



More information about the Python-list mailing list