跳过python中的for循环中的第一个条目?

跳过python中的for循环中的第一个条目?,第1张

跳过python中的for循环中的第一个条目

其他答案仅适用于序列

对于任何迭代,请跳过第一项:

itercars = iter(cars)next(itercars)for car in itercars:    # do work

如果要跳过最后一个,可以执行以下 *** 作:

itercars = iter(cars)# add 'next(itercars)' here if you also want to skip the firstprev = next(itercars)for car in itercars:    # do work on 'prev' not 'car'    # at end of loop:    prev = car# now you can do whatever you want to do to the last one on 'prev'


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5644699.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存