[Tutor] Building Starships -- object of type 'int' has no len()

Cameron Simpson cs at zip.com.au
Wed Aug 20 01:29:28 CEST 2014


On 19Aug2014 16:41, Terry--gmail <terry.kemmerer at gmail.com> wrote:
>Alan Guald:
>
>I have been trying out the different ways you suggested for doing 
>this, and have ran into a problem on making the very last one work. I 
>stuck a print statement in it to help, but I am not sure what the 
>error statement is telling me:
>
>for row in catalog2:
>    print(row)
>    for col, item in row:
>        lens[col].append(len(item))
>lens = [max(col) for col in lens]
>
>and I get the following error in 'for col, item in row:'
>
> 'ValueError: too many values to unpack (expected 2)':
>
>I don't see why it would possibly say there are too many values to 
>unpack or why it would expect only 2!

Your for-loop says:

   for col, item in row:

That iterates over each element in "row" and attempts to unpack it into the two 
variables "col" and "item". Presumably the row element has more than two items 
in it. We'd need to see to say.

Try this:

    for element in row:
        print(element)
        col, item = element
        lens[col].append(len(item))

and see what you get.

Cheers,
Cameron Simpson <cs at zip.com.au>

Archiving the net is like washing toilet paper! - Leader Kibo


More information about the Tutor mailing list