Suppose I define the following variables:
mode = \"access\"
allowed_modes = [\"access\", \"read\", \"write\"]
I currently have a type check
No, they're not equivalent. For example:
>>> mode = float('nan')
>>> allowed_modes = [mode]
>>> any(mode == allowed_mode for allowed_mode in allowed_modes)
False
>>> mode in allowed_modes
True
See Membership test operations for more details, including this statement:
For container types such as list, tuple, set, frozenset, dict, or collections.deque, the expression
x in y
is equivalent toany(x is e or x == e for e in y)
.