In article <[EMAIL PROTECTED]>, Mike C. Fletcher <[EMAIL PROTECTED]> wrote: >Python iterates over "things" (objects), of which integer numbers are >just one possible choice. The range built-in command produces ranges of >integers which are useful for tasks such as this. > >lim = 3 > >for i in range( 1, lim+1 ): > for j in range( i+1, lim+2): > for k in range( j+1, lim+3): > for l in range( k+1, lim+4): > for m in range( l+1, lim+5): > for n in range( m+1, lim+6): > print i,j,k,l,m,n > >Would be a direct translation of your code (with a few lines to make it >actually do something and a fix for the last variable name). . . . for hextuple in [(i, j, k, l, m, n) for i in range(1, lim + 1) \ for j in range (1, lim + 2) \ for k in range (1, lim + 3) \ for l in range (1, lim + 4) \ for m in range (1, lim + 5) \ for n in range (1, lim + 6)]: print hextuple
I don't think the list comprehension helps, in this case--although it hints at the temptation of an eval-able expression which is briefer. More on that, later. -- http://mail.python.org/mailman/listinfo/python-list