• + 0 comments
    def execute_command(command: list[str], current_list: list[int]) -> None:
        """Execute a command on a given list"""
        
        match command[0]:
            case "insert":
                current_list.insert(int(command[1]), int(command[2]))
            case "print":
                print(current_list)
            case "remove":
                current_list.remove(int(command[1]))
            case "append":
                current_list.append(int(command[1]))
            case "sort":
                current_list.sort()
            case "pop":
                current_list.pop()
            case "reverse":
                current_list.reverse()
            case _:
                raise ValueError("Unknown command: ", command[0])
    
    def run_commands(commands: list[str]) -> None:
        """Run a sequence of commands on a list"""
        
        current_list = []
        for line in commands:
            command = line.strip().split()
            if command:
                execute_command(command, current_list)
        
    if __name__ == "__main__":
        n = int(input())
        commands = [input() for _ in range(n)]
        run_commands(commands)