HackerRank- Python Lists

Consider a list (list = []). You can perform the following commands:

insert i e,
append e,
sort: Sort the list,
pop: Pop the last element from the list,
reverse: Reverse the list.

  1. if __name__ == '__main__':
  2. N = int(input())
  3. #n = input()
  4. l = []
  5. for _ in range(N):
  6. s = input().split()
  7. cmd = s[0]
  8. args = s[1:]
  9. if cmd !="print":
  10. cmd += "("+ ",".join(args) +")"
  11. eval("l."+cmd)
  12. else:
  13. print(l)
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube