In the following random array:
a = [[1,2,3,4], [6,7,8,9]]
Could you please tell me how to remove an item at a specific position. For example, how to remove a[1][3] ?
a[1][3]
I understand this list.pop is only used for list type DS.
list.pop
Simple, just click 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 element at a specific index:
del
>>> 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 store the value you just deleted.
In this case, a[1].remove(9) removes [1] [3]
a[1].remove(9)
python list document link