Reputation: 2723
Is there a way to shorten this if
statement?
if i != 9 or i != 23 or i != 25 or i != 33 or i !=35:
print(i)
Upvotes: 0
Views: 265
Reputation: 180471
You can use a set and check if i is not in the set:
invalid_set = {9, 23,25, 33, 35}
if i not in invalid_set:
# all good
A set lookup if O(1)
vs O(n)
with a list, tuple etc..
Upvotes: 3