In [1]:
l = list(range(10))
print(l)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [2]:
l.clear()
print(l)

[]

In [3]:
l = list(range(10))
print(l)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [4]:
print(l.pop(0))

0

In [5]:
print(l)

[1, 2, 3, 4, 5, 6, 7, 8, 9]

In [6]:
print(l.pop(3))

4

In [7]:
print(l)

[1, 2, 3, 5, 6, 7, 8, 9]

In [8]:
print(l.pop(-2))

8

In [9]:
print(l)

[1, 2, 3, 5, 6, 7, 9]

In [10]:
print(l.pop())

9

In [11]:
print(l)

[1, 2, 3, 5, 6, 7]

In [12]:
# print(l.pop(100))
# IndexError: pop index out of range

In [13]:
l = ['Alice', 'Bob', 'Charlie', 'Bob', 'Dave']
print(l)

['Alice', 'Bob', 'Charlie', 'Bob', 'Dave']

In [14]:
l.remove('Alice')
print(l)

['Bob', 'Charlie', 'Bob', 'Dave']

In [15]:
l.remove('Bob')
print(l)

['Charlie', 'Bob', 'Dave']

In [16]:
# l.remove('xxx')
# ValueError: list.remove(x): x not in list

In [17]:
l = list(range(10))
print(l)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [18]:
print([i for i in l if i % 2 == 0])

[0, 2, 4, 6, 8]

In [19]:
print([i for i in l if i % 2 != 0])

[1, 3, 5, 7, 9]

In [20]:
print(l)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [21]:
l = ['Alice', 'Bob', 'Charlie', 'Bob', 'David']
print(l)

['Alice', 'Bob', 'Charlie', 'Bob', 'David']

In [22]:
print([s for s in l if s != 'Bob'])

['Alice', 'Charlie', 'David']

In [23]:
print([s for s in l if s.endswith('e')])

['Alice', 'Charlie']

In [24]:
print(list(set(l)))

['David', 'Alice', 'Charlie', 'Bob']

In [25]:
l = list(range(10))
print(l)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [26]:
del l[0]
print(l)

[1, 2, 3, 4, 5, 6, 7, 8, 9]

In [27]:
del l[-1]
print(l)

[1, 2, 3, 4, 5, 6, 7, 8]

In [28]:
del l[6]
print(l)

[1, 2, 3, 4, 5, 6, 8]

In [29]:
l = list(range(10))
print(l)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [30]:
del l[2:5]
print(l)

[0, 1, 5, 6, 7, 8, 9]

In [31]:
l = list(range(10))
del l[:3]
print(l)

[3, 4, 5, 6, 7, 8, 9]

In [32]:
l = list(range(10))
del l[4:]
print(l)

[0, 1, 2, 3]

In [33]:
l = list(range(10))
del l[-3:]
print(l)

[0, 1, 2, 3, 4, 5, 6]

In [34]:
l = list(range(10))
del l[:]
print(l)

[]

In [35]:
l = list(range(10))
del l[2:8:2]
print(l)

[0, 1, 3, 5, 7, 8, 9]

In [36]:
l = list(range(10))
del l[::3]
print(l)

[1, 2, 4, 5, 7, 8]