Python:从数组中删除元素
1.删除第一个匹配数据:
>>> a = [0, 2, 3, 2] >>> a.remove(2) >>> a [0, 3, 2]
2.根据index删除数据:
>>> a = [9, 8, 7, 6] >>> del a[1] >>> a [9, 7, 6]
3.根据index删除数据并返回该数据:
>>> a = [4, 3, 5] >>> a.pop(1) 3 >>> a [4, 5]
4. 在循环中删除元素:
a = ["a", "b", "c", "d", "e"] for item in a[:]: print item if item == "b": a.remove(item)