747
0
Q:

remove in list python

names = ['Boris', 'Steve', 'Phil', 'Archie']
names.pop(0) #removes Boris
names.remove('Steve') #removes Steve
2
# delete by index
a = ['a', 'b', 'c', 'd']
a.pop(0)
print(a)
['b', 'c', 'd']
6
a = [10, 20, 30, 20]
a.remove(20)
# a = [10, 30, 20]
# removed first instance of argument
8
list.remove(item)
10
l = list[1, 2, 3, 4]

for i in range(len(list)):
  l.pop(i) # OR "l.remove(i)"
10
list.remove(element)
11
# animals list
animals = ['cat', 'dog', 'rabbit', 'guinea pig']

# 'rabbit' is removed
animals.remove('rabbit')

# Updated animals List
print('Updated animals list: ', animals)
3

New to Communities?

Join the community