>>> import re >>> def common_words(p1, p2): ... wordre = re.compile(r"\w+") ... w1 = wordre.findall(p1.lower()) ... w2 = wordre.findall(p2.lower()) ... cw = [] ... for word in w2: ... if word in w1: cw.append(word) ... return cw >>> pa = """I want to be very good at Python programming. Better than in Perl.""" >>> pb = """She works all day long to master Perl.""" >>> common_words(pa, pb) ['to', 'perl']
> -----Original Message----- > From: A [SMTP:[EMAIL PROTECTED]] > Sent: Monday, December 03, 2001 5:06 AM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; > [EMAIL PROTECTED] > Subject: How to compare text? > > > Hello, > How can I compare of one parragraph of text with another > paragraph?Each paragraph can have about 100 words. > For example I have the first paragraph > > I want to be very good at Python programming. Better than in Perl. > > THe second paragraph might look loke this: > > She works all day long to master Perl. > > All that I need is to find out if any of word from the second is in the > first paragraph. For the example above I should find out word > > Perl > > > What is the best and quickest way? > Thank you for help. > Ladislav > > > _______________________________________________ > ActivePython mailing list > [EMAIL PROTECTED] > http://listserv.ActiveState.com/mailman/listinfo/activepython > > _____________________________________________________________________ > This message has been checked for all known viruses by MessageLabs. _________________________________________________________________________ Alison Associates The information contained in this e-mail and any attached files is intended only for the use of the person(s) to whom it is addressed and may be privileged, confidential and exempt from disclosure under applicable law. The views of the author may not necessarily reflect the views of the Company. If you are not the intended recipient please do not copy or convey this message or any attached files to any other person but delete this message and any attached files and notify us of incorrect receipt via e-mail to [EMAIL PROTECTED] _____________________________________________________________________ This message has been checked for all known viruses by MessageLabs. _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/activepython