How to get a max string length in nested lists
<p>They is a follow up question to my earlier post (re printing table from a list of lists)</p>

<p>I'm trying t get a string max value of the following nested list:</p>

<pre><code>tableData = [['apples', 'oranges', 'cherries', 'banana'],
             ['Alice', 'Bob', 'Carol', 'David'],
             ['dogs', 'cats', 'moose', 'goose']]

for i in tableData:
    print(len(max(i))) 
</code></pre>

<p>which gives me 7, 5, 5. But "cherries" is 8 </p>

<p>what a my missing here?
Thanks.</p>

<p>You were printing the length of the max element in each row. Python computes the <code>max</code> string element as the one that is seen last in a dictionary (lexicographic sorting). What you want instead is <code>max(len(s) for s in i)</code> instead of <code>len(max(i))</code></p>

<pre><code>for row in tableData:
    print(max(len(s) for s in row))
</code></pre>

python