Start index for iterating Python list

前端 未结 8 1930
走了就别回头了
走了就别回头了 2020-12-23 02:52

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

8条回答
  •  暖寄归人
    2020-12-23 03:31

    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):
        ...
    

提交回复
热议问题