I have the following snippet of code. I’m basically trying to get the index/iterator of a particular string in a list (aside from just knowing whether it is present). Is this possible at all, or should I be using a loop-with-an-if?
bucket = [“alpha”, “beta”, “gamma”]
content = “”
if any(content == “beta” for content in bucket):
print content
Having ‘content’ as global or simply within the loop did not make a difference
Generator expressions do not leak the iterator. List comprehensions in 2.x do, but not in 3.x.