Skip to content

Instantly share code, notes, and snippets.

@kremerben
Last active October 23, 2020 18:22
Show Gist options
  • Save kremerben/30e75125e70d237c793b2b162f096330 to your computer and use it in GitHub Desktop.
Save kremerben/30e75125e70d237c793b2b162f096330 to your computer and use it in GitHub Desktop.
Recursively lowercase all elements - accepts list, str, tuple, dict, set
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
@kremerben
Copy link
Author

There's a walrus := operator in there, so you'll need to be using python3.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment