Skip to content

Instantly share code, notes, and snippets.

@avalanchy
Last active September 29, 2016 09:04
Show Gist options
  • Save avalanchy/abc3bebfd45fa317a160a1952339c2c4 to your computer and use it in GitHub Desktop.
Save avalanchy/abc3bebfd45fa317a160a1952339c2c4 to your computer and use it in GitHub Desktop.
python. Convert dict keys to uppercase. If you want to use it - don't. This mean that you should change your code.
def _uppercase_for_dict_keys(lower_dict):
upper_dict = {}
for k, v in lower_dict.items():
if isinstance(v, dict):
v = _uppercase_for_dict_keys(v)
upper_dict[k.upper()] = v
return upper_dict
def test():
examined = {
'a': 1,
'b': {
'c': 3,
}
}
expected = {
'A': 1,
'B': {
'C': 3,
}
}
assert _uppercase_for_dict_keys(examined) == expected
if __name__ == '__main__':
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment