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

Method __lt__

strings/top_k_frequent_words.py:45–64  ·  view source on GitHub ↗

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

(self, other: object)

Source from the content-addressed store, hash-verified

43 return self.count == other.count
44
45 def __lt__(self, other: object) -> bool:
46 """
47 >>> WordCount('a', 1).__lt__(WordCount('b', 1))
48 False
49 >>> WordCount('a', 1).__lt__(WordCount('a', 1))
50 False
51 >>> WordCount('a', 1).__lt__(WordCount('a', 2))
52 True
53 >>> WordCount('a', 1).__lt__(WordCount('b', 2))
54 True
55 >>> WordCount('a', 2).__lt__(WordCount('a', 1))
56 False
57 >>> WordCount('a', 2).__lt__(WordCount('b', 1))
58 False
59 >>> WordCount('a', 1).__lt__(1)
60 NotImplemented
61 """
62 if not isinstance(other, WordCount):
63 return NotImplemented
64 return self.count < other.count
65
66
67def top_k_frequent_words(words: list[str], k_value: int) -> list[str]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected