Lists Hackerrank Solution Python
For Explanation Watch Video:
Sample Input 0
12
insert 0 5
insert 1 10
insert 0 6
print
remove 6
append 9
append 1
sort
print
pop
reverse
print
Sample Output 0
[6, 5, 10]
[1, 5, 9, 10]
[9, 5, 1]
Code:
if __name__ == '__main__': N = int(input()) L = [] for i in range(N): cmd = input().split() if cmd[0]=='insert': L.insert(int(cmd[1]),int(cmd[2])) elif cmd[0]=='print': print(L) elif cmd[0]=='remove': L.remove(int(cmd[1])) elif cmd[0]=='append': L.append(int(cmd[1])) elif cmd[0]=='sort': L.sort() elif cmd[0]=='pop': L.pop() elif cmd[0]=='reverse': L.reverse()
Comments
Post a Comment