Last active
September 26, 2018 15:28
-
-
Save mdellavo/d2aa81d4239e915e7b72dcdc51c9d024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnyDict(dict): | |
""" | |
>>> AnyDict(foo=1) == {"foo": 1, "bar": 2} | |
True | |
>>> AnyDict(foo=2) == {"foo": 1, "bar": 2} | |
False | |
""" | |
def __eq__(self, other): | |
return isinstance(other, dict) and dict(other, **self) == other | |
class AnyList(list): | |
""" | |
>>> AnyList([1, 2]) == [1, 2, 3] | |
True | |
>>> AnyList([4, 5, 6]) == [1, 2, 3] | |
False | |
""" | |
def __eq__(self, other): | |
return isinstance(other, (list, tuple)) and all(element in other for element in self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment