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>Yup, <code>string[0]</code> is just <code>'N'</code></p>

<p>Regarding your statement...</p>

<blockquote>
  <p>I want to count each word in the string</p>
</blockquote>

<pre><code>&gt;&gt;&gt; s = "Nobody will give me pancakes anymore"
&gt;&gt;&gt; lens = map(lambda x: len(x), s.split())
&gt;&gt;&gt; print lens
[6, 4, 4, 2, 8, 7]
</code></pre>

<p>So, then you can do <code>lens[0]</code></p>

python list string-length