1myList.remove(item) # Removes first instance of "item" from myList
2myList.pop(i) # Removes and returns item at myList[i]
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# Example 1:
2# animals list
3animals = ['cat', 'dog', 'rabbit', 'guinea pig']
4# 'rabbit' is removed
5animals.remove('rabbit')
6# Updated animals List
7print('Updated animals list: ', animals)
8
9
10# Example 2:
11# animals list
12animals = ['cat', 'dog', 'dog', 'guinea pig', 'dog']
13# 'dog' is removed
14animals.remove('dog')
15# Updated animals list
16print('Updated animals list: ', animals)
17
18# Example 3:
19# animals list
20animals = ['cat', 'dog', 'rabbit', 'guinea pig']
21# Deleting 'fish' element
22animals.remove('fish')
23# Updated animals List
24print('Updated animals list: ', animals)
1>>> a = range(1, 10)
2>>> [x for x in a if x not in [2, 3, 7]]
3[1, 4, 5, 6, 8, 9]
4