From a736c1e0fd398b6fe1a6cc2b206f62ab3442d27f Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Thu, 11 Aug 2022 17:37:39 -0300 Subject: [PATCH] Hashing a list --- hashlist.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 hashlist.py diff --git a/hashlist.py b/hashlist.py new file mode 100644 index 0000000..080ca95 --- /dev/null +++ b/hashlist.py @@ -0,0 +1,23 @@ +import functools +import operator + +class E: + def __init__(self, some_list): + self.internal_list = some_list + + def __hash__(self): + calc_hash = functools.reduce(operator.xor, self.internal_list, 0) + print(f'Calc hash for {self.internal_list} is {calc_hash}') + return calc_hash + + def __eq__(self, other): + return self.internal_list == other.internal_list + + +content = set() +w1 = E([1, 2]) +w2 = E([1, 2]) +content.add(w1) +content.add(w2) + +print(content)