We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Basic Data Types
- Lists
- Discussions
Lists
Lists
Sort by
recency
|
2881 Discussions
|
Please Login in order to post a comment
if name == 'main': N = int(input()) # Read the number of commands lst = [] # Initialize the list
if name == 'main': N = int(input()) commands_marks ={} res = [] for _ in range(N): commands , *line = input().split() indexs = list(map(int,line)) commands_marks[commands] = indexs if commands == 'insert': res.insert(indexs[0],indexs[1]) elif commands == 'print': print(res) elif commands=='append': res.append(indexs[0]) elif commands == 'sort': res.sort() elif commands =='pop': res.pop() elif commands == 'reverse': res.reverse() elif commands =='remove': res.remove(indexs[0])
if name == 'main': lst = [] N = int(input()) for i in range(N): cho = input().lower() ch = cho.split() match ch[0]: case "insert": lst.insert(int(ch[1]), int(ch[2])) case "print": print(lst) case "remove": lst.remove(int(ch[1])) case "append": lst.append(int(ch[1])) case "sort": lst.sort() case "pop": lst.pop() case "reverse": lst.reverse() case _: print("INVALID CHOICE!")
if name == 'main': lst = [] N = int(input()) for i in range(N): cho = input().lower() ch = cho.split() match ch[0]: case "insert": lst.insert(int(ch[1]), int(ch[2])) case "print": print(lst) case "remove": lst.remove(int(ch[1])) case "append": lst.append(int(ch[1])) case "sort": lst.sort() case "pop": lst.pop() case "reverse": lst.reverse() case _: print("INVALID CHOICE!")
if name == 'main': N = int(input()) l=list() for op in range(N): inputs=input().split() operation=inputs[0] if operation=='insert': l.insert(int(inputs[1]),int(inputs[2])) elif operation=='pop' or operation=='reverse' or operation=='sort': eval(f"l.{operation}()") elif operation=='print': print(l) else: method=f"l.{operation}({int(inputs[1])})" eval(method)