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


def last_item(lt, step):
	while len(lt) >= step and step != 1:
		lt.pop(step - 1)
		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])
#测试代码
lt = [1,2,3,4,5,6,7,8,9,10]
print(last_item(lt,12))

猜你喜欢

转载自blog.csdn.net/LoveL_T/article/details/81584871