把索引为奇数的元素删除

#倒序删除
li1=[00,11,22,33,44,55,66,77,88,99]
count = len(li1)-1
while count >= 0:
    if count % 2 != 0:
        li1.pop(count)
    count -= 1
print(li1)
#切片法
li1=[00,11,22,33,44,55,66,77,88,99]
li1 = li1[::2]
print(li1)
#倒序删除
li1=[00,11,22,33,44,55,66,77,88,99]
for i in range(len(li1)-1,-1,-2): #到0的话第一个元素将打印不出来
    li1.pop(i)
print(li1)
#创建一个新列表
li1=[00,11,22,33,44,55,66,77,88,99]
li2 = []
for i in range(len(li1)):
    if i % 2 == 0:
        li2.append(li1[i])
print(li2)

 

posted @ 2020-03-27 12:51  河马哥  阅读(616)  评论(0编辑  收藏  举报