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
|
2852 Discussions
|
Please Login in order to post a comment
The challenge is in reading input, it can be read in single line as
For Python3 Platform
if name == 'main': N = int(input()) A=[] for i in range(N): com = list(map(str,input().split())) if len(com)==1: if com[0]=="print": print(A) elif com[0]=="pop": A.pop() elif com[0]=="reverse": A.reverse() elif com[0]=="sort": A.sort() continue if len(com)==2: if com[0]=="append": A.append(int(com[1])) elif com[0]=="remove": A.remove(int(com[1])) continue if len(com)==3: A.insert(int(com[1]),int(com[2]))
Self Taught and readable
**if name == 'main': N = int(input()) l=[] for _ in range (N): cmd=input().split() # Returns a list with all items sep by space i.e., ["insert","0","5"]
**