lundi 14 septembre 2020

Python - How to check if next few elements in list meet some statement

I have a huge list of values, and I want to search for pattern: if listItem == some value and next 10 items in list meet some statement, then do something. How to do this to avoid long multiple if condition code like that?

for i in range (0, len(list)):
    if list[i] == someValue and list[i+1] !=someValue and list[i+2] !=someValue and [...] and list[i+10] !=someValue: 
        doSomething()

Aucun commentaire:

Enregistrer un commentaire