MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / __eq__

Method __eq__

strings/top_k_frequent_words.py:28–43  ·  view source on GitHub ↗

>>> WordCount('a', 1).__eq__(WordCount('b', 1)) True >>> WordCount('a', 1).__eq__(WordCount('a', 1)) True >>> WordCount('a', 1).__eq__(WordCount('a', 2)) False >>> WordCount('a', 1).__eq__(WordCount('b', 2)) False >>> WordCount

(self, other: object)

Source from the content-addressed store, hash-verified

26 self.count = count
27
28 def __eq__(self, other: object) -> bool:
29 """
30 >>> WordCount('a', 1).__eq__(WordCount('b', 1))
31 True
32 >>> WordCount('a', 1).__eq__(WordCount('a', 1))
33 True
34 >>> WordCount('a', 1).__eq__(WordCount('a', 2))
35 False
36 >>> WordCount('a', 1).__eq__(WordCount('b', 2))
37 False
38 >>> WordCount('a', 1).__eq__(1)
39 NotImplemented
40 """
41 if not isinstance(other, WordCount):
42 return NotImplemented
43 return self.count == other.count
44
45 def __lt__(self, other: object) -> bool:
46 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected