python中列表重复步长删除元素

要求如下
1.返回列表中最后剩下的元素
2.传入列表,和步进值(隔几个删除数据)
3.从第一个元素起,查到步进值就删掉该元素
4.到结尾后,返回第一个元素继续累计查询

def last_item(lt, step):
    while len(lt) >= step and step != 1:
        lt.pop(step - 1)
        # print(lt)
        lt = lt[step - 1:] + lt[:step - 1]
    while len(lt) < step and len(lt) != 1:
        n = step % len(lt)
        lt.pop(n - 1)
    else:
        if step == 1:
            return (lt[-1])
        else:
            return lt[0]```

猜你喜欢

转载自blog.csdn.net/weixin_43226574/article/details/85321117