I'm new to programming and would like to ask in Python if I have a m-list of conditions and would like to know if n of these are true in a if statment:
eg:
if (a == b) or (c == d) or (e == f):
would return 1,2 or all 3 true, but I want to know if only 2 of these are true
eg:
if ((a == b) and ((c == d) or (e == f))) or (((a == b) or (c == d)) and (e == f)) or (((a == b) or (e == f)) and (c == d)):
is there any easier way to do this? What to do if (m,n) is large?
Thanks
[a == b, c == d, e == f].count(True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With