Quick actions

cmd+k|ctrl+k

Navigation

Languages

Stack

Snippet info

Language

Python

Visibility

public

Author

buse24uslu

Created

2024-03-22T09:20:56.491193Z

Updated

2024-03-22T09:34:42.642733Z

from typing import List

def execute(program: List[str]) -> List[int]:
    # initialise the stack
    stack = []
    for instruction in program:
        # print out the first item in the stack
        if instruction == "peek":
            print(stack[-1])

execute([2,5,9,7,4])
INFO