How to compare text?
Eddie Corns
eddie at holyrood.ed.ac.uk
Mon Dec 3 07:34:11 EST 2001
"A" <printers at sendme.cz> writes:
>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?
Depends a lot on how fussy you are but here's a possible starting point.
[a for a in re.split(r'\W*',para1) if a in re.split(r'\W*',para2)][:-1]
--> ['to', 'Perl']
Makes some assumptions about how paragraphs are formatted.
Eddie
More information about the Python-list
mailing list