0
Q:

python how to remove item from list

myList.remove(item) # Removes first instance of "item" from myList
myList.pop(i) # Removes and returns item at myList[i]
45
list.remove(element)
11
# removes item with given name in list
list = [15, 79, 709, "Back to your IDE"]
list.remove("Back to your IDE")

# removes last item in list
list.pop()
3
>>> a = ['a', 'b', 'c', 'd']
>>> a.remove('b')
>>> print a
['a', 'c', 'd']
7
list.remove(item)
10
l = list[1, 2, 3, 4]

for i in range(len(list)):
  l.pop(i) # OR "l.remove(i)"
10
# the list.remove(object) method takes one argument 
# the object or element value you want to remove from the list
# it removes the first coccurence from the list

generic_list = [1, 2, 2, 2, 3, 3, 4, 5, 5, 5, 6, 8, 8, 8]

generic_list.remove(1)

# The Generic list will now be:
# [2, 2, 2, 3, 3, 4, 5, 5, 5, 6, 8, 8, 8]

5
listname.remove(element)
0

New to Communities?

Join the community