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

Method __len__

data_structures/queues/linked_queue.py:55–68  ·  view source on GitHub ↗

>>> queue = LinkedQueue() >>> for i in range(1, 6): ... queue.put(i) >>> len(queue) 5 >>> for i in range(1, 6): ... assert len(queue) == 6 - i ... _ = queue.get() >>> len(queue) 0

(self)

Source from the content-addressed store, hash-verified

53 node = node.next
54
55 def __len__(self) -> int:
56 """
57 >>> queue = LinkedQueue()
58 >>> for i in range(1, 6):
59 ... queue.put(i)
60 >>> len(queue)
61 5
62 >>> for i in range(1, 6):
63 ... assert len(queue) == 6 - i
64 ... _ = queue.get()
65 >>> len(queue)
66 0
67 """
68 return len(tuple(iter(self)))
69
70 def __str__(self) -> str:
71 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected