Skip to content Skip to sidebar Skip to footer

Using Pop For Removing Element From 2d Array

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 under

Solution 1:

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]]

Solution 2:

You can use any of the three method:

  1. Remove
  2. Pop
  3. del

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]

Solution 3:

In this case, a[1].remove(9) removes a[1][3]

link to python list document

Post a Comment for "Using Pop For Removing Element From 2d Array"