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

Method __len__

data_structures/hashing/hash_map.py:297–312  ·  view source on GitHub ↗

Returns the number of items present in hashmap >>> hm = HashMap(5) >>> hm._add_item(1, 10) >>> hm._add_item(2, 20) >>> hm._add_item(3, 30) >>> hm.__len__() 3 >>> hm = HashMap(5) >>> hm.__len__() 0

(self)

Source from the content-addressed store, hash-verified

295 raise KeyError(key)
296
297 def __len__(self) -> int:
298 """
299 Returns the number of items present in hashmap
300
301 >>> hm = HashMap(5)
302 >>> hm._add_item(1, 10)
303 >>> hm._add_item(2, 20)
304 >>> hm._add_item(3, 30)
305 >>> hm.__len__()
306 3
307
308 >>> hm = HashMap(5)
309 >>> hm.__len__()
310 0
311 """
312 return self._len
313
314 def __iter__(self) -> Iterator[KEY]:
315 yield from (item.key for item in self._buckets if item)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected