I am trying to traverse through a dictionary and capitalize all of the keys if they are strings. I am getting a RunTime error for this:
for k, v in ref_dict.items():
if isinstance(k, str):
ref_dict[k.upper()] = v
else:
ref_dict[k] = v
How do I avoid something like this? Or, better, how do I improve the code in order to solve this more elegantly?