nested for loop

Tor Iver Wilhelmsen tor.iver.wilhelmsen at broadpark.no
Mon May 10 17:52:13 EDT 2004


wjb131 at web.de (Wolfgang Buechel) writes:

> for (a,b,c,d) in [(x,y,z,t)  for x in range(M)
>                              for y in range(M)
>                              for z in range(M)
>                              for t in range(M)] :
>    matr = [[a,b],[c,d]]

Try assigning range(M) to a variable instead of creating four copies
of it. For larger ranges, experiment using xrange instead.



More information about the Python-list mailing list