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

Guido van Rossum guido@beopen.com
Tue, 11 Jul 2000 13:24:05 -0500


> I sent the message below to the 11 developers here in the office this
> morning.  They all have 10+ years experience with C, and 2-3 years with
> C++, Java, or both.  None have used Python (I'm working on it :-), but two
> have extensive Perl experience, and one worked on and with functional
> languages in grad school.  The question was:
> 
>     OK, folks, language question.  Given the statement:
> 
>         for x in [10, 20, 30]; y in [1, 2]:
>             print x+y
> 
>     (note that the second list is shorter than the first), would you
>     expect to see:
> 
>     (A) 'x' and 'y' move forward at the same rate:
> 
>         11
>         22
> 
>     (B) 'y' goes through the second list once for each value of 'x':
> 
>         11
>         12
>         21
>         22
>         31
>         32
> 
>     (C) an error message because the two lists are not the same length?
> 
>     Votes to me, please.
> 
>     Thanks,
>     Greg
> 
> *Everyone* voted (B).  As useful as this capability is, I therefore think
> the proposed syntax is likely to mislead.

Thanks for user testing!

I just wished you had shown it to them with two lists of the same
length.  That's the normal case, and I believe that the different
length must have tricked them into believing that it couldn't possibly
be (A).

I'd like to run the experiment with that change.  Do you have another
set of guinea pigs around?

--Guido van Rossum (home page: http://dinsdale.python.org/~guido/)