Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python "in" Comparison of Strings of Different Word Length

I am working through a database of names with possible duplicate entries and attempting to identify which we have two of, unfortunately the formatting is a bit less than optimal and some entries have their first name, middle name, last name or maiden names mashed into one string and some have just first and last.

I need a way to see if say 'John Marvulli' matches 'John Michael Marvulli' and be able to do an operation on those matches. However if you try:

>>> 'John Marvulli' in 'John Michael Marvulli'
False

It returns False. Is there an easy way to compare two strings in this manner to see if one name is contained in another?

like image 248
Joel Smith Avatar asked Jan 15 '23 04:01

Joel Smith


1 Answers

You need to split the strings and look for the individual words:

>>> all(x in 'John Michael Marvulli'.split() for x in 'John Marvulli'.split())
True
like image 197
Wooble Avatar answered Jan 21 '23 14:01

Wooble