List comprehensions
Albert Hofkamp
hat at se-46.wpa.wtb.tue.nl
Wed Dec 22 05:12:54 EST 1999
On 21 Dec 1999 18:20:27 +0100, Magnus L. Hetland <mlh at vier.idi.ntnu.no> wrote:
>hat at se-46.wpa.wtb.tue.nl (Albert Hofkamp) writes:
>
>> PS I'd like to have a stronger visual separation between the result
>> expression, and the iterations and conditions, so '|' looks better to me
>> than ',' .
>> This is especially true if you do not start with an iteration, like in
>>
>> [ x>6, x>5 ]
>>
>> (Bonus-points for the people who understand what the result is
>> :-) )
>
>How could you tell, as long as you haven't defined an order over, or
>even a range for x? The result could be practically anything.
If you look at it as an iteration, then the equivalent Python code is
res = []
if x>5:
res := res + [x>6]
So depending on the value of x, you'd get [], [false], or [true]
Albert
---
Look ma, windows without Windows !!
More information about the Python-list
mailing list