I need to know if any element in a list meets a certain criteria. To do so, I want to use a generator expression inside an any() function, but the output seems to misbehave:
>>> x
[0, 0, 0]
>>> gen = (z==1 for z in x)
>>> any(gen)
True
If I instead use a list, I get the right answer:
>>> x
[0, 0, 0]
>>> com = [z==1 for z in x]
>>> any(com)
False
I've tried this on two different Windows 7 computers, one with python 2.7.2 and one with 2.7.3. Both return the wrong answer. I had someone try it on their machine which has python 2.7.5 and he got the right answer. Does anybody know what's going on here?