Skip to content

Instantly share code, notes, and snippets.

@mdellavo
Last active September 26, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdellavo/d2aa81d4239e915e7b72dcdc51c9d024 to your computer and use it in GitHub Desktop.
Save mdellavo/d2aa81d4239e915e7b72dcdc51c9d024 to your computer and use it in GitHub Desktop.
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