IndexError: list index out of range, this is a lists problem on hackerrank

Viewed 28
if __name__ == '__main__':
    N = int(input())
    ls=[]
    for _ in range(0,N):
        cd, *x=input().split()
        x=list(map(int,x))
        if cd == 'insert':
            ls.insert(x[0],x[1])
        elif cd == 'print':
            print(ls)
        elif cd == 'remove':
            ls.remove(x[1])
        elif cd == 'append':
            ls.append(x[1])
        elif cd == 'sort':
            ls.sort()
        elif cd == 'pop':
            ls.pop()
        elif cd == 'reverse':
            ls.reverse()

I am getting the following error: IndexError: list index out of range on line 7

I am not able to figure out why..!!

0 Answers
Related