I have a program where based on a specific value from a dictionary, I
call a different function. Currently, I've implemented a bunch of
if..elsif statements to do this, but it's gotten to be over 30 right
now and has gotten rather tedious. Is there a more efficient way to do
this?
Code:
value = self.dictionary .get(keyword)[0]
if value == "something" :
somethingClass. func()
elsif value == "somethingElse" :
somethingElseCl ass.func()
elsif value == "anotherthi ng":
anotherthingCla ss.func()
elsif value == "yetanotherthin g":
yetanotherthing Class.func()
Is it possible to store these function calls in a dictionary so that I
could just call the dictionary value?
call a different function. Currently, I've implemented a bunch of
if..elsif statements to do this, but it's gotten to be over 30 right
now and has gotten rather tedious. Is there a more efficient way to do
this?
Code:
value = self.dictionary .get(keyword)[0]
if value == "something" :
somethingClass. func()
elsif value == "somethingElse" :
somethingElseCl ass.func()
elsif value == "anotherthi ng":
anotherthingCla ss.func()
elsif value == "yetanotherthin g":
yetanotherthing Class.func()
Is it possible to store these function calls in a dictionary so that I
could just call the dictionary value?
Comment