Last active
September 29, 2016 09:04
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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