Start index for iterating Python list

2019-03-08 10:01发布

What is the best way to set a start index when iterating a list in Python. For example, I have a list of the days of the week - Sunday, Monday, Tuesday, ... Saturday - but I want to iterate through the list starting at Monday. What is the best practice for doing this?

7条回答
干净又极端
2楼-- · 2019-03-08 10:27

islice has the advantage that it doesn't need to copy part of the list

from itertools import islice
for day in islice(days, 1, None):
    ...
查看更多
登录 后发表回答