I have several variables some of which I need to change on condition.
test = 'foo'
a, b, c = None, None, None
if test == 'foo':
a = 1
if test == 'bar':
b = 2
else:
c = 3
I'd like to use the dict approach described here, but how can I modify it to change multiple variables? Perfectly I want it to work like this:
options = {'foo': ('a',1), 'bar': ('b',2)}
reassign_variables(options,test, ('c',3))
Or this can't be done without creating a function and writing all the conditions separately?
Aucun commentaire:
Enregistrer un commentaire