Python遍历删除元素
摘要:
需求:有一个列表:ls = [1,2,3,4,5,6],要求删除其中的偶数如果是下面这种方法,在遍历的过程中删除,会有问题for i in range(len(ls)): if ls[i]%2 == 0: del ls[i]异常:IndexError: list index ou... 阅读全文
posted @ 2015-11-12 22:25 李俊伟 阅读(227) 评论(0) 推荐(0) 编辑
posted @ 2015-11-12 22:25 李俊伟 阅读(227) 评论(0) 推荐(0) 编辑
posted @ 2015-11-12 14:04 李俊伟 阅读(230) 评论(0) 推荐(0) 编辑
posted @ 2015-11-12 01:59 李俊伟 阅读(5712) 评论(0) 推荐(1) 编辑