gpt4 book ai didi

python - 改进从 0 以外的索引开始迭代 python 列表中每个项目的代码

转载 作者:太空宇宙 更新时间:2023-11-04 04:40:32 25 4
gpt4 key购买 nike

<分区>

在这段代码中,我想遍历列表中从索引 [4] 开始到索引 [3] 结束的每个项目。有什么方法可以改进我编写代码以实现此目的的繁琐方式吗?我试过“for a in days[4:3] 但这只迭代索引 4 到 6 而不是 0-3;

mar = int(input())
days = ["0","1","2","3","4","5","6"]
count = 0
x = "0"
while count < mar:
for a in days[4],[5],[6],[0],[1],[2],[3]:
if count < mar:
count += 1
x = a
print(x)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com