HackerRank Solution: LISTS

Sakshi Singh
1 min readApr 3, 2019

--

(IN PYTHON3)

if __name__ == ‘__main__’:

n = int(input())

l=[]

for _ in range(n):

line = input().split()

comd,num = line[0], line[1:]

nos = list(map(int, num))

if comd==’insert’:

l.insert(nos[0],nos[1])

elif comd==’print’:

print(l)

elif comd==’pop’:

l.pop()

elif comd==’sort’:

l.sort()

elif comd==’reverse’:

l.reverse()

elif comd == ‘append’:

l.append(nos[0])

elif comd==’remove’:

l.remove(nos[0])

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sakshi Singh
Sakshi Singh

No responses yet

Write a response