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've done the <em>length of the maximum word</em>.  This gives the wrong answer because words are ordered <a href="https://en.wikipedia.org/wiki/Lexicographical_order" rel="nofollow">lexicographically</a>:</p>

<pre><code>&gt;&gt;&gt; 'oranges' &gt; 'cherries'
True
</code></pre>

<p>What you probably wanted is the <em>maximum of the lengths of words</em>:</p>

<pre><code>max(len(word) for word in i)
</code></pre>

<p>Or equivalently:</p>

<pre><code>len(max(i, key=len))
</code></pre>

python