Yes, I meant split(). Was a typo :) On Wed, Jun 20, 2012 at 3:56 PM, Prasad, Ramit <ramit.pra...@jpmorgan.com>wrote:
> Please always post back to the list. > > > Nope, strip() was intended so we get a list back instead of a string. > Need > > the list for iteration down below that. > > >> > para = paragraph.strip('.').strip(',').strip().split() > >> I think you want replace not strip. > >> > >> See http://docs.python.org/library/stdtypes.html#string-methods > > No, you are wrong. If you had looked at the link (or tested the code) you > would find strip() does not do what you think it does. > > What do you mean by "we get a list back instead of a string"? strip does > not return a list...it returns a string. split is what returns the list for > iteration. > > > >>> paragraph = "This paragraph contains words once, more than once, and > possibly not at all either. Figure that one out. " > >>> para = paragraph.strip('.').strip(',').strip().split() > >>> print para > ['This', 'paragraph', 'contains', 'words', 'once,', 'more', 'than', > 'once,', 'and', 'possibly', 'not', 'at', 'all', 'either.', 'Figure', > 'that', 'one', 'out.'] > > Note the inclusion of 'once,' and 'either.' and 'out.'. Use replace to > remove > punctuation instead and then just compare words. Most probably you want to > lower() > or upper() the entire paragraph to be thorough, otherwise 'This' and > 'this' will > be counted separately. > > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor