I'm refactoring spaghetti code, and it has a piece like this:
template_dict = {
"value": "",
"isIncreased": False,
"isDecreased": False
}
my_dict = {
"current_half_result": {
"home": template_dict,
"draw": template_dict,
"away": template_dict
},
"full_time_result": {
"home": template_dict,
"draw": template_dict,
"away": template_dict
},
"current_half_over_under": {
"$1_5": {
"over": template_dict,
"under": template_dict
},
"handicap": ""
},
"full_time_over_under": {
"$2_5": {
"over": template_dict,
"under": template_dict
},
"handicap": ""
},
"next_goal": {
"home": template_dict,
"no_goal": template_dict,
"away": template_dict
}
}
As you see my_dict variable and has the same value in all leaf keys - template_dict. How can I remove repeating from code in a way that code doesn't get slower than the current example and also increase readability and cleanliness of the code. Speed is an important factor, because, this piece of code gets 3-6 hundred times a second in my server. And I don't wont to increase number of lines much or create additional function etc.
P.S. I didn't write that code, so don't judge me. Due to strong coupling in code, I can't make a big change at once. For full code, check this link