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

Method __repr__

data_structures/queues/double_ended_queue.py:439–455  ·  view source on GitHub ↗

Implements representation of the deque. Represents it as a list, with its values between '[' and ']'. Time complexity: O(n) >>> our_deque = Deque([1, 2, 3]) >>> our_deque [1, 2, 3]

(self)

Source from the content-addressed store, hash-verified

437 return Deque._Iterator(self._front)
438
439 def __repr__(self) -> str:
440 """
441 Implements representation of the deque.
442 Represents it as a list, with its values between '[' and ']'.
443 Time complexity: O(n)
444 >>> our_deque = Deque([1, 2, 3])
445 >>> our_deque
446 [1, 2, 3]
447 """
448 values_list = []
449 aux = self._front
450 while aux is not None:
451 # append the values in a list to display
452 values_list.append(aux.val)
453 aux = aux.next_node
454
455 return f"[{', '.join(repr(val) for val in values_list)}]"
456
457
458if __name__ == "__main__":

Callers

nothing calls this directly

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected