I have a list with names, I am trying to search list by passing a string, as output I need all the names from the list that matches to the word.
EX:
ls = ['Hello from AskPython', 'Hello', 'Hello boy!', 'HiHello', 'Hellotent', 'Tenthello']
sub = "Hello"
matches = [match for match in ls if sub in match]
print(matches)
['Hello from AskPython', 'Hello', 'Hello boy!', 'HiHello', 'Hellotent', 'Tenthello']
But Expected output is :
['Hello from AskPython', 'Hello', 'Hello boy!']
In the above example "Hello" appeared in between name, I need to exclude such words.