Python's list.__contains__ method has semantics that check for whether any element of the list is equivalent to the given parameter. This can be demonstrated with the following experiment:
>>> x = list(range(5)) >>> y = list(range(5)) >>> id(x) 3695160 >>> id(y) 3689488 >>> x == y True >>> x is y False >>> sample = [ x ] >>> y in sample TrueNotice that the sample list has x as an element, yet it reports the distinct list y to be in the list, because y is equivalent to x. Had the semantics been looking for the precise identity, the last containment query would have returned False.
A simpler example can be constructed noting that floats and
ints are distinct but can be equivalent, that is
>>> data = [4] >>> 4.0 in data Trueand conclude that the containment check for lists suffices if it locates an equivalent element.