xxxxxxxxxx
# delete by index
a = ['a', 'b', 'c', 'd']
a.pop(0)
print(a)
['b', 'c', 'd']
xxxxxxxxxx
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
xxxxxxxxxx
myList = ['Item', 'Item', 'Delete Me!', 'Item']
del myList[2] # myList now equals ['Item', 'Item', 'Item']
xxxxxxxxxx
names = ['Boris', 'Steve', 'Phil', 'Archie']
names.pop(0) #removes Boris
names.remove('Steve') #removes Steve
xxxxxxxxxx
list_ = ["lots", "of", "items", "in", "a", "list"]
# Remove an item by index and get its value: pop()
>>> list_.pop(0)
'lots'
>>> list_
["of", "items", "in", "a", "list"]
# Remove an item by value: remove()
>>> list_.remove("in")
>>> list_
["of", "items", "a", "list"]
# Remove items by index or slice: del
>>> del list_[1]
>>> list_
['of', 'a', 'list']
# Remove all items: clear()
>>> list_.clear()
>>> list_
[]
xxxxxxxxxx
a = ['apple', 'carrot', 'lemon']
b = ['pineapple', 'apple', 'tomato']
# This gives us: new_list = ['carrot' , 'lemon']
new_list = [fruit for fruit in a if fruit not in b]