Last active
May 18, 2022 13:58
-
-
Save schuettc/3875da7458e3573646599e70b7b17a61 to your computer and use it in GitHub Desktop.
Recursively Capitalize Keys - Python
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 capitalize_keys(d): | |
| for k, v in d.copy().items(): | |
| if isinstance(v, dict): | |
| d.pop(k) | |
| d[f"{k[0].upper() +k[1:]}"] = v | |
| capitalize_keys(v) | |
| else: | |
| d.pop(k) | |
| d[f"{k[0].upper() +k[1:]}"] = v | |
| return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment