I'd like to check if a string contains an element from a list:
l = ['S', 'R', 'D', 'W', 'V', 'Y', 'H', 'K', 'B', 'M']
s = 'YTG'
The first solution is:
for i in l:
if i in s:
print i
This seems inefficient though. I tried the following code but it gives me the last element of the list 'M' instead of 'Y':
if any(i in s for i in l):
print i
I was wondering what is the problem here?
Thanks!