Searching name in string from list of names in python -


def get_name(string, list_names):     """     inputs:         string: string analyzed         list_names: list of names among whom looking     """     name in list_names:         begin_pattern = re.compile("^\name")         if begin_pattern.search(string):             return name 

hi need search names have in string. list

 list_names = ['lamarcus aldridge',      'damian lillard',      'wesley matthews',      'arron afflalo',      'robin lopez',      'nicolas batum',      'chris kaman'] 

function returns no error returns no matches @ all. get_name("damian lillard makes 18-foot jumper (allen crabbe assists)", list_names) should return damian lillard. can me. thanks

try :

import re def get_name(string, list_names):     name in list_names:         match = re.search(r'\b%s\b'%(name),string)         if match:             return name  string ="damian lillard makes 18-foot jumper (allen crabbe assists)" list_names = ['lamarcus aldridge','damian lillard','wesley matthews','arron afflalo','robin lopez','nicolas batum','chris kaman']  print(get_name(string,list_names)) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -