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
Post a Comment