I need a constant (dictionary with values and default return value if there are no defined value for a key). Searching for any ways to simplify the code.
Without a default value I can simply define a dictionary like this:
REDUCE_VALUE = {
"honda": 0.95,
"suzuki": 0.85,
"yamaha": 0.87
}
But with a default value it looks not so good:
from collections import defaultdict
REDUCE_VALUE = defaultdict(lambda: "0.9")
REDUCE_VALUE["honda"] = 0.95
REDUCE_VALUE["suzuki"] = 0.85
REDUCE_VALUE["yamaha"] = 0.87
getmethod of the standard dictionary returns a default value when the given key is missing. \$\endgroup\$