Removing Items from a List
Removal by a Target Value
# .remove() example
a_list = ['apple', 'oranges', 'kiwi', 'honeydew', 'apple']
a_list.remove('apple')
a_list.remove('kiwi')
print('a_list:', a_list)a_list: ['oranges', 'honeydew', 'apple']Removal by Index
# .pop() example
a_list = ['apple', 'oranges', 'kiwi', 'honeydew', 'apple']
removed1 = a_list.pop()
a_list.pop(2)
print('a_list:', a_list)
print('removed1:', removed1)Removing All Items in a List
Introduction to del
delMAJOR DANGER: Deletion During Iteration
Last updated