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

Cameron Simpson cs at zip.com.au
Wed Aug 20 01:33:42 CEST 2014


On 19Aug2014 16:41, Terry--gmail <terry.kemmerer at gmail.com> wrote:
>Alan Guald:
[...]
>lens = [max(col) for col in lens]
[...]
>Also, the list comprehension you have used on the final line reminds 
>me that I would really like to understand comprehensions better. Is 
>there some info on the Internet that starts very basic concerning 
>comprehensions and explains step by step in complexity how they are 
>structured and what the computer is doing?

The line above is essentially equivalent to this:

   lens_orig = lens
   lens = []
   for col in lens_orig:
     lens.append(max(col))

It just assembles a list of values, each being max(col), for each element in 
lens. The mucking with "lens" and "lens_orig" above is only because you're 
replacing "lens" with the new list.

>Just looking at the code setting there inside the list brackets and 
>know what the output is going to be, reminds me of a programmed cell 
>of a spreadsheet....kind of.

It is very like that, if you consider two spreadsheet columns, the first with 
the original values in "lens" and the second having "max(col)" for each.

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

ERROR 155 - You can't do that.  - Data General S200 Fortran error code list


More information about the Tutor mailing list