Stutter a stack using an auxiliary stack. Args: stack: A list representing a stack (bottom to top). Returns: The stack with each value duplicated. Examples: >>> first_stutter([3, 7, 1, 14, 9]) [3, 3, 7, 7, 1, 1, 14, 14, 9, 9]
(stack: list[int])
| 17 | |
| 18 | |
| 19 | def first_stutter(stack: list[int]) -> list[int]: |
| 20 | """Stutter a stack using an auxiliary stack. |
| 21 | |
| 22 | Args: |
| 23 | stack: A list representing a stack (bottom to top). |
| 24 | |
| 25 | Returns: |
| 26 | The stack with each value duplicated. |
| 27 | |
| 28 | Examples: |
| 29 | >>> first_stutter([3, 7, 1, 14, 9]) |
| 30 | [3, 3, 7, 7, 1, 1, 14, 14, 9, 9] |
| 31 | """ |
| 32 | storage_stack: list[int] = [] |
| 33 | for _ in range(len(stack)): |
| 34 | storage_stack.append(stack.pop()) |
| 35 | for _ in range(len(storage_stack)): |
| 36 | val = storage_stack.pop() |
| 37 | stack.append(val) |
| 38 | stack.append(val) |
| 39 | |
| 40 | return stack |
| 41 | |
| 42 | |
| 43 | def second_stutter(stack: list[int]) -> list[int]: |