Python List (Python列表)
list.pop(index) (list.pop(指数))
>>> l = ['a', 'b', 'c', 'd']
>>> l.pop(0)
'a'
>>> l
['b', 'c', 'd']
>>>
del list[index] (del list [index])
>>> l = ['a', 'b', 'c', 'd']
>>> del l[0]
>>> l
['b', 'c', 'd']
>>>
These both modify your original list. (这些都会修改您的原始列表。)
Others have suggested using slicing: (其他人建议使用切片:)
- Copies the list (复制列表)
- Can return a subset (可以返回一个子集)
Also, if you are performing many pop(0), you should look at collections.deque (此外,如果您执行许多pop(0),您应该查看collections.deque)
from collections import deque
>>> l = deque(['a', 'b', 'c', 'd'])
>>> l.popleft()
'a'
>>> l
deque(['b', 'c', 'd'])
- Provides higher performance popping from left end of the list (从列表的左端提供更高性能的弹出)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…