In the below random array:
a = [[1,2,3,4],
[6,7,8,9]]
Could you please tell me how to remove element at a specific position. For example, how would I remove a[1][3]
?
I understand list.pop
is used for only list type DS here.
Simple, just pop on the list item.
>>> a = [[1,2,3,4], [6,7,8,9]]
>>> a[1].pop(3)
>>> a
[[1, 2, 3, 4], [6, 7, 8]]
You should use del
to remove an item at a specific index:
>>> a = [[1,2,3,4], [6,7,8,9]]
>>> del a[1][3]
>>> a
[[1, 2, 3, 4], [6, 7, 8]]
>>>
list.pop
should only be used when you need to save the value you just removed.
You can use any of the three method:
a = [[1,2,3,4], [6,7,8,9]]
1- Remove a[1].remove(a[1][3])
2- Pop a[1].pop(3)
3-Del del a[1][3]