I'm really stuck in evaluating Boolean expressions. See the code:
def f(A):
if A=='a' or A=='b' or A=='c' ...:
return True
return False
Is there any convenient and elegant way to do this when A can equal to even more strings?
If you do this check often and/or have a lot of possible values consider using a set. Lookup time for a set is O(1), lookup time for a list is O(n).
if A in {'a', 'b', 'c', ...}:
# do something
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