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

Terry--gmail terry.kemmerer at gmail.com
Thu Aug 21 08:25:58 CEST 2014


Thanks Japhy Bartlett!

[[0] for i in range(5)]

Works! I converted to fit into my routine as:


lens = [[] for i in range(len(catalog2[0]))]     <<---- the new statement
for row in catalog2:
     for col, item in enumerate(row):
         lens[col].append(len(item))
lens = [max(col) for col in lens]
print(lens)

My result is:

[6, 17, 5, 9, 12, 7, 0, 0, 0]          <<--------THAT IS THE CORRECT ANSWER!

Perfect!

Peter Otten
Thanks! Those work also!

Danny Yoo
Thanks for the Documentation on creating multidimensioned lists! 
Interesting read! And now I know why my first attempts to get 
multi-dimensions from an equation failed.

Alan Gauld
YUP!

lens = [ [] for n in catalog2[0] ]

Works!
--And greatly simplifies how I first constructed this!
Thanks!

Thanks Everyone! This gets me going again....


More information about the Tutor mailing list