Having trouble finding the greatest length of whitespace in string
<p>I need to find the greatest length of white space in the string. No idea whats wrong. </p>

<pre><code>def check1(x):
    cc = ()
    for i in x:
        if i != " ":
            lis.append(cc)
            cc=0
        else:
            cc +=1
            new.append(cc)
            print(cc)
</code></pre>

<p>I'm not sure whats wrong, its not adding to the appending list. </p>

<p>Use <code>regex</code>es and builtin <code>max</code>:</p>

<pre><code>import re
max_len = max(map(len, re.findall(' +', sentence)))
</code></pre>

<hr>

<p><code>re.findall(' +', sentence)</code> will find all the occurrences of one or more whitespaces.</p>

<p><code>map(len, ...)</code> will transform this array into the array of the corresponding string lengths.</p>

<p><code>max(...)</code> will get the highest value of these string lengths. </p>

python string