Lists | HACKER RANK

Asked: Rahul Kumar Ranjan |Category: Python

n=int(input())

l=[]

for i in range (n):

x=input().split(" ")

com=x[0]

if com=="insert":

l.insert(int(x[1]),int(x[2]))

elif com=="print":

print(l)

elif com=="remove":

l.remove(int(x[1]))

elif com=="append":

l.append(int(x[1]))

elif com=="sort":

l.sort()

elif com=="pop":

if len(l)!=0:

l.pop()

elif com=="reverse":

l.reverse()


46 views0 comments

Recent Posts

See All

Binary string reduction in Python

Asked: Sudeep |Category: Python x=int(input("Enter the value of x : ")) for i in range(x): n=int(input("Enter the value of n : ")) y=input("Enter the value of y : ") l=list(y) k=0

"Believe you can and you're halfway there"