Skip to content

Instantly share code, notes, and snippets.

@AdamGold
Last active March 24, 2019 13:10
Show Gist options
  • Save AdamGold/c946a818231345c0869134fced6b56a1 to your computer and use it in GitHub Desktop.
Save AdamGold/c946a818231345c0869134fced6b56a1 to your computer and use it in GitHub Desktop.
class Entry(object):
def __init__(self, key: str, value=None):
self.key = key
self.value = value
@property
def hash(self) -> int:
"""return entry's hash"""
def __repr__(self):
return f"<Entry hash={self.hash}, key={self.key}, value={self.value}>"
def __str__(self):
return str(self.value)
def __eq__(self, other: object) -> bool:
"""Check equation with other entries, e.g dict['a'] == dict['b']""""
if not isinstance(other, Entry):
return NotImplemented
return self.value == other.value
def compare_hash(self, other: object) -> bool:
"""compare keys and hashes with different entry"""
if not isinstance(other, Entry):
return NotImplemented
return self.hash == other.hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment