From:                   "A" <[EMAIL PROTECTED]>
To:                     [EMAIL PROTECTED], [EMAIL PROTECTED],
        [EMAIL PROTECTED]
Subject:                How to compare text?
Send reply to:          [EMAIL PROTECTED]
Priority:               normal
Date sent:              Mon, 3 Dec 2001 11:06:04 +0100

>
> 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
>


Hallo Ladislav, I have written a small progam, which will work as you expect. I
hope so. I think this is a fast way to compare two paragraphs.

wbg
Günter




def CreateDict(par):
            
   
   #Remove some chars
   for char in ('.',';',','):
        par = par.replace(char,"")
                                
    
                                
   words = par.split(' ')                                   
   dPar = {}
    
   for word in words:
       dPar[word] = 1

   return dPar       


def Diff(par1,par2):
    
    dPar1 = CreateDict(par1) 
    dPar2 = CreateDict(par2)
     
    lCommon = [] 
    for word in dPar2.keys():
        if dPar1.has_key(word):
            lCommon.append(word)  
            
    return lCommon    
        
    


 
 
 
 
def main(): 
    lCommonWords = Diff("I want to be very good at Python programming. Better than in 
Perl.",
        "She works all day long to master Perl.")        
        
    print "Common Words: ", lCommonWords        
    
 
main()    

Reply via email to