forked from krishna14kant/Data-Structures-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHasher.py
More file actions
25 lines (17 loc) · 628 Bytes
/
Hasher.py
File metadata and controls
25 lines (17 loc) · 628 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Emp:
def __init__(self, emp_name, id):
self.emp_name = emp_name
self.id = id
def __eq__(self, other):
# Equality Comparison between two objects
return self.emp_name == other.emp_name and self.id == other.id
def __hash__(self):
# hash(custom_object)
return hash((self.emp_name, self.id))
if __name__ == __main__ :
emp = Emp('Ragav', 12)
print("The hash is: %d" % hash(emp))
# We'll check if two objects with the same
# attribute values have the same hash
emp_copy = Emp('Ragav', 12)
print("The hash is: %d" % hash(emp_copy))