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

Marc Tompkins marc.tompkins at gmail.com
Wed Aug 20 22:56:04 CEST 2014


On Wed, Aug 20, 2014 at 1:38 PM, Terry--gmail <terry.kemmerer at gmail.com> wrote:
> Marc, my understanding is, is that:
>
>     lens[col].append(len(item))
>
> -should be building a mirror image of my list of lists called catalog2,
> which currently has 9 columns by x number of rows, and that we are plugging
> into these positions, the sizes of all the elements in that block of data.

What's important is how you defined lens:
>  lens = [0] * len(catalog2[0])

That's a list of integers, as far as I can tell without running it
(I'm away from an interpreter at the moment.)  So no, you cannot do
lens[col].append(whatever), because - as the error message said -
'int' object has no attribute 'append'.

There might be some misunderstanding about what list.append(whatever)
does - it adds "whatever" to the end of list.  It does NOT assign
values to elements that already exist; to do that, you need to do
assignment by index.  So maybe this is what you're looking for?:
>     lens[col] = len(item)



> So, I completely don't understand why we would eliminate the positioning of
> which list we are referencing in lens by saying:
>
>     lens.append(len(item))
>
> It seems to me that, that statement would put the entire block of element
> sizes into one list, and the next MAX statement would then yield only a
> single number, which would be the largest size element it encounted in the
> whole of catalog2!
>
> Or am I really missing the boat here? :)

>     lens.append(len(item))
will append a single integer to lens.  I'm afraid I don't quite follow
the bit about "the next MAX statement", as I've lost the thread of
what your larger project is trying to accomplish...  In any case,
max() _should_ only return a single number, no?


More information about the Tutor mailing list