mult-indexed xrange?

Emile van Sebille emile at fenx.com
Fri Mar 1 16:23:16 EST 2002


"Huaiyu Zhu" <huaiyu at gauss.almadan.ibm.com> wrote in message
news:slrna7vqm8.13q.huaiyu at gauss.almadan.ibm.com...
> The generator facility in 2.2 allows me to do something cool that I
always
> wanted: looping around multiple indices with just one for-statement,
as the
> following code does.  Is this available with some built-in functions?

for (x,y) in [(i,j) for i in range(2) for j in range(3) ]:
    print x,y
0 0 0
0 0 1
0 1 0
0 1 1
0 2 0
0 2 1
1 0 0
1 0 1
1 1 0
1 1 1
1 2 0
1 2 1
Press any key to continue . . .

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list