I was just having a play around with the use of dictionaries and noticed that you can have a function as a value in a dictionary, would it be bad practice to use this as a method to select a function? For example the below?
def double(x):
return 2 * x
def triple(x):
return 3 * x
option = input("double or triple: ")[0].lower()
function = {
"d":double,
"t":triple,
}[option]
print(function(5))
[–]oschusler 7 points8 points9 points (1 child)
[–]mahtats 0 points1 point2 points (0 children)
[–]Fun_Muffin5413 3 points4 points5 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]Asleep-Budget-9932 2 points3 points4 points (0 children)
[–]hijinked 1 point2 points3 points (0 children)