Skip iterations in enumerated list object (python)

前端 未结 6 2152
清歌不尽
清歌不尽 2021-02-14 19:33

I have the code

for iline, line in enumerate(lines):
    ...
    if :
        

I would like, as you c

6条回答
  •  礼貌的吻别
    2021-02-14 19:57

    As Padraic Cunningham states, you can do this with a while loop, you can also use a dictionary to replace the if-statement:

    iline = 0
    skip = {True:5, False:1}
    
    while iline > len(lines):
        line = lines[iline]
        ...
        iline += skip[condition]
    

提交回复
热议问题