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.
If that is true, then lens[col] is creating lists which contain the
sizes of the elements in that particular column.
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? :)
Thanks for your thoughts!
--Terry
On 08/20/2014 02:26 PM, Marc Tompkins wrote:
On Aug 20, 2014 12:07 PM, "Terry--gmail" <terry.kemme...@gmail.com
<mailto:terry.kemme...@gmail.com>> wrote:
>
> Alan Gauld
>
> Hi!
> We are not quite out of the woods on this last example you gave me.
It now seems to be complaining
> that it doesn't want to append an integer to the list or that this
isn't the place to use '.append' -- I am probably interpreting it's
complaint wrong:
>
> Python 3.3
>
> If I run this last piece of code that we just added 'enumerate(row)' to:
>
> lens = [0] * len(catalog2[0])
> for row in catalog2:
>
> for col, item in enumerate(row):
> print(col, item, len(item))
>
> lens[col].append(len(item))
> lens = [max(col) for col in lens]
>
> My result is:
>
> 0 Drives 6 <<---- my print statement result
>
> Traceback (most recent call last):
> File "/home/justme/1a_Computer_Related/Python/scripts/scratch.py",
line 43, in <module>
> lens[col].append(len(item))
> AttributeError: 'int' object has no attribute 'append'
>
Once again you're confusing the list with its contents. lens is a
list; lens[col] is an integer. lens.append(whatever) should do the trick.
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor