mardi 2 mai 2017

The best way to replace multiple if-statementes on dictionary python

i have a multiple conditions.

if you == 1 or you == 2:
    one.put(argument)
elif you == 3:
    return None
elif you == 4:
    two.put(argument)
elif you == 5:
    three.put(argument)
elif you == 6:
    four.put(argument)
elif you == 7:
    five.put(argument)
elif you == 8:
    six.put(argument)
elif you == 9:
    seven.put(argument)
elif you == 10:
    eight.put(argument)
elif you == 11:
    nine.put(argument)
elif you == 12:
    ten.put(argument)

I want to change it on something with use dictionary, but i have exceptions in:

if you == 1 or you == 2:
    one.put(argument)
elif you == 3:
    return None

How you think, what the best way to do this with these exceptions ?

Aucun commentaire:

Enregistrer un commentaire