[Tutor] How to compare text?

Andrei Kulakov ak@silmarill.org
Mon, 03 Dec 2001 05:14:25 -0500


On Mon, Dec 03, 2001 at 11:06:04AM +0100, A wrote:
> 
> 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?

Something along these lines:

paragraph1words = paragraph1.split()
paragraph2words = paragraph2.split()

common_words = []
for word in paragraph1words:
    if word in paragraph2words:
        common_words.append(word)
        
print "These words are in both paragraphs:",
for word in common_words:
    print word,

> Thank you for help.
> Ladislav
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org