Trouble with for loop

Paul Hankin paul.hankin at gmail.com
Tue Nov 6 11:11:22 CET 2007


Shriphani wrote:
> Hello,
> I want to try something like:
>
> for (a, b, c, d, e, f) in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
> ####
>
> When I do that I get an error:
> TypeError: unpack non-sequence
>
> My main intention is to state that each of the variables namely a, b,
> c, ## can take value from 1 to 9.
> How do I go about this ?

Do you want the variables to be indepenedent?

for a in range(1, 10):
    for b in range(1, 10):
        for c in range(1, 10):
            for d in range(1, 10):
                for e in range(1, 10):
                     for f in range(1, 10):
                          ####

Or all the same?
for a in range(1, 10):
    b = c = d = e = f = a

Whatever you're doing though, there's almost certainly a better way.

--
Paul Hankin




More information about the Python-list mailing list