I have a list A = ['B' , 'G' , 'G' , 'B' , 'B' , 'G']
The value of index 3 in A list is = 'B'
.
I want to remove that.Is there any way to remove specific element from a list?
If i use A.remove('B')
,then it will remove first βBβ. But i want to remove 'B'
, which index number is 3.
Use the function βdelβ!
In your example the solution is:
del A[3]
Try it!
1 Like
If the specific element is at the end of the array you can use:
- del A[-1] (Indexes in python also can be usefd for the end to the start in the form (-1, -2, β¦)
- A.pop() (that gives you the deleted element as a result but remove it)
1 Like