python 3.x - Removing second element of a list -
i working on code has list of integers such list1 = [1,2,3,4,5] , want print out 1 3 4 5 print out "new list" without second element.
you can use indexes slicing (i assume want keep original list intact):
>>> list1[0:1] + list1[2:] [1, 3, 4, 5] so in general skip i element (when 0 included):
>>> list1[0:i] + list1[i+1:]
Comments
Post a Comment