Fork me on GitHub

【总结】两种方法删除一个列表中索引是偶数项的内容

#-----------------方法一--------------------------
list1 = [1,2,3,4,5,6,7,8,9]
list2 = []
for i in range(len(list1)):
    if i % 2 ==1:
        list2.append(list1[i])
    else:
        continue
print(list2)

#-----------------方法二---------------------------
list1 = [1,2,3,4,5,6,7,8,9]
i = 0
while i < len(list1):
    del list1[i]
    i+=1
print(list1)
posted @ 2020-01-15 10:49  抖落烟火  阅读(1131)  评论(0编辑  收藏  举报