'How to get partial match of a substring in a list of string?

I have a list of items like gmail, google, outlook and another list with mx records of a domain like mail.protection.outlook.com, gmail-smtp.google.com etc. I wanted to see if the second list contains any word from the first list (even partial matches as it contains dot and hyphen). How can I achieve this?



Solution 1:[1]

You can use the "in" operator like so:

fullstr = "stackoverflow"
substr = "over"

if substr in fullstr:
    print "found!"
else:
    print "not found!"

Solution 2:[2]

test_list = ["ab", "ba","abc","acb","bac"]
substr = "ab"
res = [i for i in test_list if substr in i]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RonanCraft
Solution 2 Alex