2

I have strings with owner names and I need to identify whether they contain a last name twice.

For example, I may have an owner name that reads "BENNETT MCCARL & ARNETTE BENNETT".

I would like to return True if any word is found in the string twice, and False if all words in the string are unique.

Does anyone know how I can do this using Python?

PolyGeo
  • 1,340
  • 3
  • 26
  • 59
Kristen
  • 31
  • 2
  • This question has arisen from http://gis.stackexchange.com/questions/179164/need-to-find-strings-that-contain-the-same-word-twice, and so its terminology needs some work. I'll try to do that now. – PolyGeo Feb 03 '16 at 00:11

1 Answers1

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

You can split the name into a word list by spaces, and then transform this list into a set. Its length will become shorter after duplicated words has been eliminated.

YCFlame
  • 1,251
  • 1
  • 15
  • 24