lst = ['a', 'b', 'c', 'aa', 'bb', 'cc']
def findexact(lst):
i=0
key = ['a','g','t']
while i < len(lst):
if any(item in lst[i] for item in key):
print lst[i]
i+=1
findexact(lst)
in the above code, the result comes out to be:
'a'
'aa'
I would like the result to be:
'a'
What is the right way to use any() to get the right result?
Based on my interpretation of your question, it looks like you want to find which item in key is in lst. This would be the way to do it:
def findexact(lst):
key = ['a','g','t']
for k in key:
if k in lst:
print k
return k
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With