[Python-Dev] Re: questionnaire about zip and for loops
Huaiyu Zhu
NO_SPAM_hzhu@knowledgetrack_dot_com.python.org
Fri, 21 Jul 2000 19:08:22 -0700
You need to add a Reply-To: line so people wouldn't send to the list by
mistake. It is also difficult for many editors and mailers to deal with
long lines.
Huaiyu
In comp.lang.python, you wrote:
>This is a slightly reduced version of a questionnaire run by Greg Wilson on some CS
>grad students.
>
>I'd like to use the readers of comp.lang.python as guinea pigs this time.
>
>PLEASE SEND THE RESULTS TO mailto:peter@schneider-kamp.de - DON'T SEND THEM TO THE LIST
>
>Thanks for your time,
>Peter
>
>-----------------------------------------------------------------------------------------
>
>The single and double loop below print the output shown:
>
>for x in [10, 20, 30]: for x in [10, 20, 30]:
> print x for y in [1, 2, 3]:
> print x+y
>10 11
>20 12
>30 13
> 21
> 22
> 23
> 31
> 32
> 33
>
>Match each of the following example for-loops to an output. Only make one cross per line.
>Please consider each example on its own.
>(Note that several examples may print the same thing.)
>
>
> (1) (2) (3) (4) (5) (6)
>
> 11 11 11 11 error ??
> 22 12 22 12
> 33 13 21
> 21 22
> 22 31
> 23 32
> 31
> 32
> 33
>
>(A)
>for (x, y) in [[10, 1], [20, 2], [30, 3]]: x o o o o o
> print x+y
>
>(B)
>for [x, y] in zip([10, 20, 30], [1, 2, 3]): x o o o o o
> print x+y
>
>(C)
>for [x, y] in zip([10, 20, 30], [1, 2]): o o x o o o
> print x+y
>
>(D)
>for x; y in [10, 20, 30]; [1, 2, 3]: o o o o x o
> print x+y
>
>(E)
>for x; y in [10, 20, 30]; [1, 2]: o o o o x o
> print x+y
>
>(F)
>for x in [10, 20, 30]; y in [1, 2, 3]: o x o o o o
> print x+y
>
>(G)
>for x in [10, 20, 30]; y in [1, 2]: o o o x o o
> print x+y
>
>
>--
>Peter Schneider-Kamp ++47-7388-7331
>Herman Krags veg 51-11 mailto:peter@schneider-kamp.de
>N-7050 Trondheim http://schneider-kamp.de
>