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)
| 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 | |
| 458 | if __name__ == "__main__": |