so I have a bunch of if and life statements one after another and each condition does something different depending on the condition how do I condense that down into lesser more efficient code? I have something like:
if ...:
if ...:
if ...:
if ...:
do something
elif ..:
do something else
elif...:
do something else
elif ...:
do something
elif ...:
do some other stuff
else:
do this
is there a way to use a dictionary here where the keys are conditions and the values are the action taken based on the value each line under each if or life statement will only do one or two things max? how would I implement that inside a function that takes the condition as arguments?
Aucun commentaire:
Enregistrer un commentaire