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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.