[Python-ideas] Order of loops in list comprehension

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Oct 22 19:47:01 EDT 2016


C Anthony Risinger wrote:
> Erlang/Elixir (sorry after 6 years python this is what I do now!) 
> does it the same way as python:
> 
>  >>> [{X, Y} || X <- [1,2,3], Y <- [a,b]].
> [{1,a},{1,b},{2,a},{2,b},{3,a},{3,b}]
> 
> Here X is the outer loop.
> 
> I think the confusion stems from doing it both ways at the same time.

If the semicolon syntax I suggested were available,
you'd be able to choose either order, and maybe even
mix them in the one comprehension. Not sure if that's
a good thing or not...

-- 
Greg


More information about the Python-ideas mailing list