How to remove specific element from a list in python

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:

  1. del A[-1] (Indexes in python also can be usefd for the end to the start in the form (-1, -2, …)
  2. A.pop() (that gives you the deleted element as a result but remove it)
1 Like

Thank you so much :smiling_face_with_three_hearts:

1 Like