I want to determine if a list contains a certain string, so I use a generator expression, like so:
g = (s for s in myList if s == myString)
any(g)
Of course I want to inline this, so I do:
any((s for s in myList if s == myString))
Then I think it would look nicer with single parens, so I try:
any(s for s in myList if s == myString)
not really expecting it work. Surprise! it does!
So is this legal Python or just something my implementation allows? If it's legal, what is the general rule here?
my_string in my_list
was the first thing I tried, but it failed to find a string that was present. I concluded that it was doing object comparison rather than value comparison, which is what I need. I'll check again. – Gpo