python - How to get a max string length in nested lists -


they follow question earlier post (re printing table list of lists)

i'm trying t string max value of following nested list:

tabledata = [['apples', 'oranges', 'cherries', 'banana'],              ['alice', 'bob', 'carol', 'david'],              ['dogs', 'cats', 'moose', 'goose']]  in tabledata:     print(len(max(i)))  

which gives me 7, 5, 5. "cherries" 8

what missing here? thanks.

you've done length of maximum word. gives wrong answer because words ordered lexicographically:

>>> 'oranges' > 'cherries' true 

what wanted maximum of lengths of words:

max(len(word) word in i) 

or equivalently:

len(max(i, key=len)) 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -