For example:
def foo():
print 'foo'
return 1
if any([f() for f in [foo]*3]):
print 'bar'
I thought the above code should output:
foo
bar
instead of :
foo
foo
foo
bar
Why ? how can I make the “short-circuit” effect ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Deconstruct your program to see what is happening:
You are already creating a list and passing to any and have printed it 3 times.
This is fed to if statement:
Solution: Pass a generator to any