Start index for iterating Python list

前端 未结 8 1947
走了就别回头了
走了就别回头了 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:33

    You can use slicing:

    for item in some_list[2:]:
        # do stuff
    

    This will start at the third element and iterate to the end.

提交回复
热议问题