Python-函数-写函数,获取传入列表的所有奇数位索引对应的元素,并将其作为新列表返回

'''
写函数,获取传入列表的所有奇数位索引对应的元素,并将其作为新列表返回。
例如:
传入:[34,23,52,352,352,3523,5]
返回:[23,352,3523]
'''

def lst(list):
    lst1=[]
    for i in range(len(list)):
        if i%2==1:
            lst1.append(list[i])
    return lst1
ret=lst([34,23,52,352,352,3523,5])
print(ret)
原文地址:https://www.cnblogs.com/cy-zjs/p/13194905.html