This post gets me half way to where I want to go. I'd like to know which string the following code found, but on my machine it isn't working:
a = ['a', 'b', 'c']
str = "a123"
if any(x in str for x in a):
print x
This produces the error: "NameError: name 'x' is not defined". How does one determine which string (within a
) was found? In other words, based on which string was found in the list, I want to do something specific in the code that follows, thus I need to know what x
was when the condition was true. I'm using python 3.5.0