A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-July/006110.html below:

[Python-Dev] re: list comprehension / pop quiz

[Python-Dev] re: list comprehension / pop quizKa-Ping Yee pingster@ilm.com
Tue, 11 Jul 2000 12:40:22 -0700 (PDT)
On Tue, 11 Jul 2000, Greg Wilson wrote:
>         for x in [10, 20, 30]; y in [1, 2]:
>             print x+y
[...]
>     (A) 'x' and 'y' move forward at the same rate:
>     (B) 'y' goes through the second list once for each value of 'x':
>     (C) an error message because the two lists are not the same length?
[...]
> *Everyone* voted (B).

Okay, i just thought of another answer to this.

Scream at me if you find this hideous.

    for x in [10, 20, 30] while y in [1, 2]:
        print x+y

My previous message proposed colons to separate the clauses of
a list comprehension, which i now realize makes dict comprehensions
impossible (or at least a little strange-looking).  If we use "while",
the lack of semicolons means that we can do parallel loops in
list-comps without colons, which in turn enables dict-comps.

<ducking for cover>


-- ?!ng




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4