1# removes item with given name in list
2list = [15, 79, 709, "Back to your IDE"]
3list.remove("Back to your IDE")
4
5# removes last item in list
6list.pop()
7
8# pop() also works with an index..
9list.pop(0)
10
11# ...and returns also the "popped" item
12item = list.pop()
1# Basic syntax:
2my_list.remove(element)
3
4# Note, .remove(element) removes the first matching element it finds in
5# the list.
6
7# Example usage:
8animals = ['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']
9animals.remove('rabbit')
10print(animals)
11--> ['cat', 'dog', 'guinea pig', 'rabbit'] # Note only 1st instance of
12# rabbit was removed from the list.
13
14# Note, if you want to remove all instances of an element, convert the
15# list to a set and back to a list, and then run .remove(element) E.g.:
16animals = list(set['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']))
17animals.remove('rabbit')
18print(animals)
19--> ['cat', 'dog', 'guinea pig']
1names = ['Boris', 'Steve', 'Phil', 'Archie']
2names.pop(0) #removes Boris
3names.remove('Steve') #removes Steve
1myList = ["hello", 8, "messy list", 3.14] #Creates a list
2myList.remove(3.14) #Removes first instance of 3.14 from myList
3print(myList) #Prints myList
4myList.remove(myList[1]) #Removes first instance of the 2. item in myList
5print(myList) #Prints myList
6
7
8#Output will be the following (minus the hastags):
9#["hello", 8, "messy list"]
10#["hello", "messy list"]
1>>> a=[1,2,3]
2>>> a.remove(2)
3>>> a
4[1, 3]
5>>> a=[1,2,3]
6>>> del a[1]
7>>> a
8[1, 3]
9>>> a= [1,2,3]
10>>> a.pop(1)
112
12>>> a
13[1, 3]
14>>>