Determining if string contains same word more than once using Python? -


i have strings owner names , need identify whether contain last name twice.

for example, may have owner name reads "bennett mccarl & arnette bennett".

i return true if word found in string twice, , false if words in string unique.

does know how can using python?

def check(name):     words = name.split()     return (len(words) > len(set(words))) 

you can split name word list spaces, , transform list set. length become shorter after duplicated words has been eliminated.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -