vendredi 8 juin 2018

how to avoid if..then for elements in a long list of counters [duplicate]

This question already has an answer here:

I have a list of counters in my code and if it is possible I'd like to avoid to write an if condition for each of them.

I figured out the following solution in python 3, but it doesn't works.... how to?

a=0
b=0
c=0

for element in a list:
     <do something>
     for i in ['a', 'b', 'c']:
     if element == i:
         i += 1 

Aucun commentaire:

Enregistrer un commentaire