Python - Find Items in a List that are also a String

I don't really use the filter command much, until I needed to see whether something in a string was also in a list..

myList = ['fart', 'boff', 'squit','trump']
myString = "I really couldn't help but trump and fart all night"
print filter(lambda x : x in myString, myList)
>>>['fart', 'trump']

No comments:

Post a Comment