List comprehensions

Alexander Williams thantos at chancel.org
Tue Dec 21 23:06:40 EST 1999


On 21 Dec 1999 16:54:16 GMT, Albert Hofkamp <hat at se-46.wpa.wtb.tue.nl>
wrote:

>With parallel iteration, you are doing two things at a time.
>If you want to be able to do this in Python (a new question !!),
>then imho you'd need a single language construct which looks like 'see,
>I am iterating over both lists here, watch out !'

More and more /this/ construct is looking to be map().  Consider the
results of doing:

    >>> 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.


>   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 :-) )

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

-- 
Alexander Williams (thantos at gw.total-web.net)           | In the End,
  "Join the secret struggle for the soul of the world." | Oblivion
  Nobilis, a new Kind of RPG                            | Always
  http://www.chancel.org                                | Wins



More information about the Python-list mailing list