I have a variable foo, which points to a string, "bar"
foo = "bar"
I have a list, called whitelist.
If whitelist is not empty, the elements contained are a whitelist.
If whitelist is empty, then the if statement permits any string.
I have implemented this as follows
whitelist = ["bar", "baz", "x", "y"]
if whitelist and foo in whitelist:
print("bar is whitelisted")
# do something with whitelisted element
if whitelist, by my understanding, checks if whitelist returns True. whitelist will be False if whitelist is empty. If whitelist contains elements, it will return True.
However, the real implementation of this contains:
- lots of strings to check e.g. `"bar", "baz", "x", "y", "a", "b"
- lots of whitelists to check against
Therefore, I was wondering if there is a more computationally efficient way of writing the if statement. It seems like checking the existence of whitelist each time is inefficient, and could be simplified.