Correct solution
if tag in ('/event', '/organization', '/business'):
It uses not only the in operator, which is ideal for this purpose, but also uses a (immutable) tuple, so the python interpreter can optimize it better than a (mutable) list.
Test showing that tuples are faster than lists:
In [1]: import timeit In [2]: t1 = timeit.Timer('"b" in ("a", "b", "c")') In [3]: t2 = timeit.Timer('"b" in ["a", "b", "c"]') In [4]: t1.timeit(number=10000000) Out[4]: 0.7639172077178955 In [5]: t2.timeit(number=10000000) Out[5]: 2.240161895751953
source share