For example:
list = [1,7,2,8,9,2,7,9,2,8,2]
How can I remove two of the "2" without removing the others?
For example:
list = [1,7,2,8,9,2,7,9,2,8,2]
How can I remove two of the "2" without removing the others?
You can find the index of the one(s) you want to delete and use the function pop(index) to delete it/them.
Exemple:
your_list.pop(5) # Delete the 5th element of your list
Here's a little doc: https://www.programiz.com/python-programming/methods/list/pop
This should work by removing an i
element n
times from a list arr
.
arr = [1,7,2,8,9,2,7,9,2,8,2]
def remove(arr, i, n = 1):
for _ in range(n):
arr.remove(i)
remove(arr, 2, 3)
print(arr)