HackerRank- Python Lists


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

insert i e,
print,
remove,
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)

download android app