When I am using python for scripting I usually think in the pythonic way of everything. I have recently notice that I can do
if a == 0 or b == 0 or c == 0: # something happens
that way
if 0 in [a,b,c]: # something happens
This way is much more generic and I could dynamically fulfil the list with the items that I need to compare.
There exists a pythonic way for this case?
if a == 0 and b == 0 and c == 0: # something happens
In both case, comparing with 0 it's just an example. It could be something like this
if a == "foo" and b == "foo" and c == "foo": # something happens
And I need a pythonic way for that.
Answer
I leave my answer at the description because I can't reopen the question to post my answer. The pythonic way for that case requires the all()
function.
if all(v == 0 for v in (a,b,c)): #something happens