MCPcopy
hub / github.com/keon/algorithms / first_stutter

Function first_stutter

algorithms/stack/stutter.py:19–40  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

17
18
19def 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
43def second_stutter(stack: list[int]) -> list[int]:

Callers 1

test_stutterMethod · 0.90

Calls 1

popMethod · 0.45

Tested by 1

test_stutterMethod · 0.72