Last active
October 23, 2020 18:22
-
-
Save kremerben/30e75125e70d237c793b2b162f096330 to your computer and use it in GitHub Desktop.
Recursively lowercase all elements - accepts list, str, tuple, dict, set
This file contains 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 lowercase_everything(obj): | |
""" Recursively lowercase all elements - accepts list, str, tuple, dict, set """ | |
if isinstance(obj, dict): | |
return {k.lower(): _lowercase(v) for k, v in obj.items()} | |
elif (t := type(obj)) in (list, set, tuple): | |
return t(_lowercase(o) for o in obj) | |
elif isinstance(obj, str): | |
return obj.lower() | |
return obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a walrus
:=
operator in there, so you'll need to be using python3.8.