Sorry, it seems like I was not clear enough in that statement. I should have written something like &quot;counting how many times each word occured&quot; insted of &quot;counting words&quot;.<div><br><div class="gmail_quote">

2012/6/20 mariocatch <span dir="ltr">&lt;<a href="mailto:mariocatch@gmail.com" target="_blank">mariocatch@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div>Hello,</div><div> </div><div>Not sure if this is what you&#39;re trying to solve, although it sounds like it based on your leading statement.</div><div>I think what you have is more complicated than it needs to be for something that simple:</div>


<div>Why not something like this?</div><div> </div><div><em>    paragraph = &quot;&quot;&quot;I have been learning Python and trying little bits of coding for a while. Recently I tried to have a paragraph and create a list of its words, then counting those words. Here is the code:&quot;&quot;&quot;</em></div>


<div><em>    splitParagraph = paragraph.strip().split(&#39; &#39;)<br>    print len(splitParagraph) # yields 36<br>    print splitParagraph # yields a list [] of each word separated by split()</em></div><p><em></em> </p>

<div>
-Mario<br><br><br></div><div class="gmail_quote"><div><div class="h5">On Wed, Jun 20, 2012 at 8:53 AM, Oğuzhan Öğreden <span dir="ltr">&lt;<a href="mailto:ogreden@gmail.com" target="_blank">ogreden@gmail.com</a>&gt;</span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div><div class="h5">
Hi,<div><br></div><div>I have been learning Python and trying little bits of coding for a while. Recently I tried to have a paragraph and create a list of its words, then counting those words. Here is the code:</div><div>


<br>

</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




import re</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




a = &quot;&quot;&quot;Performs the template substitution, returning a new string. mapping is any dictionary-like \</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




object with keys that match the placeholders in the template. Alternatively, you can provide keyword \</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




arguments, where the keywords are the placeholders. When both mapping and kws are given and there \</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




are duplicates, the placeholders from kws take precedence.&quot;&quot;&quot;</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">b = []</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




c = 0</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




for y in a.split(&quot; &quot;):</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">        </span>b.append(y.lower())</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">        </span>if  re.search(&quot;,&quot;, y) != None:</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">                </span>c = b.index(y.lower())</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">                </span>b.remove(y.lower())</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">                </span>b.insert(c, y.strip(&quot;,&quot;).lower())</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">        </span>b.sort()</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">        </span></blockquote>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">b.extend([&quot;you&quot;])</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




<span style="white-space:pre-wrap">                </span></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




count = 0</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">




for x in b:</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">        </span></blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">        </span>count = b.count(x)</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">        </span></blockquote>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">        </span>if count &gt; 1:</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">                </span>c = b.index(x)</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">                </span>if b[c+1] != x is True:</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">                        </span>print &quot;%s listede %d tane var.&quot; % (x, count)</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">        </span>else:</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span style="white-space:pre-wrap">                </span>print &quot;%s listede %d tane var.&quot; % (x, count)</blockquote>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><br></blockquote></blockquote><div><br></div><div>And here are the questions:</div>




<div><br></div><div><ul><li>This code doesn&#39;t print for the items that occur more than one time. Why?</li><li>And actually as I was writing, I realized that &quot;if b[c+1]&quot; may return an error if the last item on the list occured more than one, however, it didn&#39;t even if a manually made the last item occur two times. Was my initial expectation a false one? If not, how could I turn it into a b[c-1] so that it will not fail in first item?</li>




</ul><div>Thanks,</div></div><div>Oğuzhan</div>
<br></div></div>_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br>
</blockquote></div><br></div>