给出一个名字列表,我想在另一个列表中找到他们的全名。
我拥有的是:
group = [ "Calderon Juan", "Bramel Joshua", "Davis Decurious", "Hernandez
Hilda", "Martinez Francisco", "Dixon Quanzie", "Johnson Landry", "York
Alex", "Mercer Jacob", "Perez Ricardo", "Bowie Emily", "Huber Grayson",
"Stucker Nicholas", "Cole Christopher", "Caron Michael", "Caronni Vas",
"Rittenberry Grant"]
people_to_find = ["Caron", "York", "Dixon", "David", "Andrew"]
for s in group:
for item in people_to_find:
if item in s:
print item + ", found in: " + s
输出结果为:
Dixon, found in: Dixon Quanzie
York, found in: York Alex
Caron, found in: Caron Michael
Caron, found in: Caronni Vas
它并不完美,因为它没有完全匹配。例如,
Caron, found in: Caronni Vasly
我想知道的是“Caron”,没有任何一个词有“Caron”的部分。
此外,我将短名单改为:
people_to_find = ["Caron ", "York ", "Dixon ", "David ", "Andrew "]
什么是好的解决方案? 谢谢。