mercredi 8 juin 2016

Python double simultaneous 'IF' conditions

Is it possible to loop through a list and, for each item in the list, go down two conditional IF paths?

For example, consider the below pseduocode:

for item in list:
    if some_variable == item:
        somevariable += 1
    else:
        somevariable -= 1
    andif some_other_varible == item:
        some_other_variable += 1
    else:
        some_other_variable -= 1

So each item is compared to two variables, and an action is performed on each variable depending on the value of the item.

Aucun commentaire:

Enregistrer un commentaire