set vs list
__contains__ dunder ( ). ,
>>> 1 in [1,2]
>>> list.__contains__([1,2],1)
>>> True
:
>>> [1,2] in [1,2,3]
>>> False
? - . Infact -. , Hash-Table. sets , .. O(1) list, O(n). , in , __contains__ hash , , __hash__.
python, : TypeError: unhashable type: 'list'. , , .
In short membership tests, you cannot run on sets with a non-displayable object. Generally speaking, all volatile objects are (list, sets, dict)not shaken.
source
share