List comprehensions

Albert Hofkamp hat at se-46.wpa.wtb.tue.nl
Wed Dec 22 05:28:52 EST 1999


On Wed, 22 Dec 1999 04:06:40 GMT, Alexander Williams
				<thantos at chancel.org> wrote:
>    >>> map(None, range(1, 11),
>    >>>           range(1, 11))
>
>You get:
>
>    >>> [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7),
>         (8,8), (9, 9), (10, 10)]
>
>... which is just the parallel construct you wanted.

I see.
It appears I have a lot of Python to learn :-)

If it is that easy to construct a list of tuples, then I'd think to drop
parallel iteration if only to prevent cluttering of the semantics of the
list comprehension.

>>   [ x>6, x>5 ]
>>
>Easy, a two element list consisting of two Boolean values dependent on
>whether or not the pre-defined value x makes said statement true.  :)

ROFL !

Does this lead to the conclusion that there are some syntactical
problems with list comprehension ?


Another matter is scoping. I hope that code like

 i := 30
 ys := [ 4 ]
 xs := [ i ] + [ i+15, for i in ys ] + [ i+1 ]

is well-defined.
I'd like to have xs == [ 30, 19, 31 ] at the end, but I am too new to
Python to say anything useful about scoping.
Is this what you'd expect, and is it feasible ?


Albert
---
Look ma, windows without Windows !!



More information about the Python-list mailing list