<div>Sorry for the double-post.</div><div> </div><div>I don't think I am wrong either. Replace doesn't return a list of words in the way that my code sample was setup to do.</div><div>How would you solve it with replace? Maybe an example prove the point better.</div>
<div> </div><div>-Mario<br><br></div><div class="gmail_quote">On Wed, Jun 20, 2012 at 4:10 PM, mariocatch <span dir="ltr"><<a href="mailto:mariocatch@gmail.com" target="_blank">mariocatch@gmail.com</a>></span> wrote:<br>
<blockquote 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" class="gmail_quote">Yes, I meant split(). Was a typo :)<div class="HOEnZb"><div class="h5">
<br><br><div class="gmail_quote">On Wed, Jun 20, 2012 at 3:56 PM, Prasad, Ramit <span dir="ltr"><<a href="mailto:ramit.prasad@jpmorgan.com" target="_blank">ramit.prasad@jpmorgan.com</a>></span> wrote:<br>
<blockquote 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" class="gmail_quote">Please always post back to the list.<br>
<div><br>
> Nope, strip() was intended so we get a list back instead of a string. Need<br>
> the list for iteration down below that.<br>
<br>
</div><div>>> > para = paragraph.strip('.').strip(',').strip().split()<br>
>> I think you want replace not strip.<br>
>><br>
>> See <a href="http://docs.python.org/library/stdtypes.html#string-methods" target="_blank">http://docs.python.org/library/stdtypes.html#string-methods</a><br>
<br>
</div>No, you are wrong. If you had looked at the link (or tested the code) you<br>
would find strip() does not do what you think it does.<br>
<br>
What do you mean by "we get a list back instead of a string"? strip does<br>
not return a list...it returns a string. split is what returns the list for<br>
iteration.<br>
<div><br>
<br>
>>> paragraph = "This paragraph contains words once, more than once, and possibly not at all either. Figure that one out. "<br>
</div><div>>>> para = paragraph.strip('.').strip(',').strip().split()<br>
</div>>>> print para<br>
['This', 'paragraph', 'contains', 'words', 'once,', 'more', 'than', 'once,', 'and', 'possibly', 'not', 'at', 'all', 'either.', 'Figure', 'that', 'one', 'out.']<br>
<br>
Note the inclusion of 'once,' and 'either.' and 'out.'. Use replace to remove<br>
punctuation instead and then just compare words. Most probably you want to lower()<br>
or upper() the entire paragraph to be thorough, otherwise 'This' and 'this' will<br>
be counted separately.<br>
<div><div><br>
<br>
Ramit<br>
<br>
<br>
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology<br>
712 Main Street | Houston, TX 77002<br>
work phone: <a href="tel:713%20-%20216%20-%205423" target="_blank" value="+17132165423">713 - 216 - 5423</a><br>
<br>
--<br>
<br>
This email is confidential and subject to important disclaimers and<br>
conditions including on offers for the purchase or sale of<br>
securities, accuracy and completeness of information, viruses,<br>
confidentiality, legal privilege, and legal entity disclaimers,<br>
available at <a href="http://www.jpmorgan.com/pages/disclosures/email" target="_blank">http://www.jpmorgan.com/pages/disclosures/email</a>.<br>
_______________________________________________<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>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>