Counting sub-element in string?
<p>Say I have a <code>string = "Nobody will give me pancakes anymore"</code></p>

<p>I want to count each word in the string. So I do <code>string.split()</code> to get a list in order to get <code>['Nobody', 'will', 'give', 'me', 'pancakes', 'anymore']</code>.</p>

<p>But when I want to know the length of <code>'Nobody'</code> by inputing <code>len(string[0])</code> it only gives me <code>1</code>, because it thinks that the 0th element is just <code>'N'</code> and not <code>'Nobody'</code>. </p>

<p>What do I have to do to ensure I can find the length of the whole word, rather than that single element?</p>

<p>You took the first letter of <code>string[0]</code>, ignoring the result of the <code>string.split()</code> call.</p>

<p>Store the split result; that's a list with individual words:</p>

<pre><code>words = string.split()
first_worth_length = len(words[0])
</code></pre>

<p>Demo:</p>

<pre><code>&gt;&gt;&gt; string = "Nobody will give me pancakes anymore"
&gt;&gt;&gt; words = string.split()
&gt;&gt;&gt; words[0]
'Nobody'
&gt;&gt;&gt; len(words[0])
6
</code></pre>

python list string-length