Last active
March 24, 2019 13:10
-
-
Save AdamGold/c946a818231345c0869134fced6b56a1 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 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