0

Is there alternative way to do it without using function pop ?

Input :a_list = [1,2,3,4,5,6,7]

a_list.pop(1)

Output : a_list = [1,3,4,5,6,7] 

I have tried something but it says TypeError: 'list' object is not callable after my try

shahaf
  • 4,750
  • 2
  • 29
  • 32
Theooc
  • 31
  • 3
  • You want to remove the second element from the list? – igg Jan 25 '20 at 10:52
  • Yes, you can add slice before and after the element you want to get rid of (`a_list = a_list[0:1] + a_list[2:]`) or you could `del` the element. Why would you do that like that though, I am not sure. :) – Ondrej K. Jan 25 '20 at 10:54
  • You can take a look to https://stackoverflow.com/questions/11520492/difference-between-del-remove-and-pop-on-lists – nucsit026 Jan 25 '20 at 12:01

2 Answers2

1

You might use del keyword in order to do it:

a_list = [1,2,3,4,5,6,7]
del a_list[1]
print(a_list)  # [1, 3, 4, 5, 6, 7]
Daweo
  • 31,313
  • 3
  • 12
  • 25
0

You can use slicing:

a_list = [1,2,3,4,5,6,7]
print(a_list)
a_list = a_list[:1] + a_list[2:]
print(a_list)
igg
  • 2,172
  • 3
  • 10
  • 33