0
Q:

python list remove item by value

# delete by index
a = ['a', 'b', 'c', 'd']
a.pop(0)
print(a)
['b', 'c', 'd']
6
list.remove(element)
11
l = ['Alice', 'Bob', 'Charlie', 'Bob', 'Dave']
print(l)
# ['Alice', 'Bob', 'Charlie', 'Bob', 'Dave']

l.remove('Alice')
print(l)
# ['Bob', 'Charlie', 'Bob', 'Dave']
2
import random


#Let's say that we have a list of names.
listnames = ['Miguel', 'James', 'Kolten']
#Now, I choose a random one to remove.
removing = random.choice(listnames)
#And to delete, I do this:
listnames.remove(remove)
-1

New to Communities?

Join the community