Martin
0
Q:

delete from list python

myList = ['Item', 'Item', 'Delete Me!', 'Item']

del myList[2] # myList now equals ['Item', 'Item', 'Item']
6
list.remove(element)
11
l = list[1, 2, 3, 4]
l.pop(0) #remove item by index
l.remove(3)#remove item by value
#also buth of the methods returns the item
2
# delete by index
a = ['a', 'b', 'c', 'd']
a.pop(0)
print(a)
['b', 'c', 'd']
6
myList = ['Item', 'Item', 'Delete Me!', 'Item']

myList.pop(2) # myList now equals ['Item', 'Item', 'Item']
0
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