Arista EOS components often process temporary command or event state in last-in, first-out order. Design a stack abstraction that stores generic elements and supports standard operations efficiently.
Implement stack_operations(operations), which receives a sequence of commands and returns the results produced by query commands. Internally, define a stack that stores values without assuming a specific element type.
Each operation is a list whose first item is a command:
['push', value]: Add value to the top of the stack. This produces no result.['pop']: Remove and return the top value. Return None if the stack is empty.['peek']: Return the top value without removing it. Return None if the stack is empty.['size']: Return the number of stored elements.['is_empty']: Return True when the stack has no elements, otherwise False.Return a list containing results from pop, peek, size, and is_empty commands in their original order. Values may be integers, strings, or booleans, and pushed values are never None.
def stack_operations(operations):