Skip to content

Instantly share code, notes, and snippets.

@ben181231
Created December 8, 2016 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben181231/6c8aa783bd320c2c15f7daa8f3b0e699 to your computer and use it in GitHub Desktop.
Save ben181231/6c8aa783bd320c2c15f7daa8f3b0e699 to your computer and use it in GitHub Desktop.
# Ref. https://gist.github.com/href/1319371
from collections import namedtuple
def convert(dictionary):
for key, value in dictionary.items():
if isinstance(value, dict):
dictionary[key] = convert(value)
if isinstance(value, list):
dictionary[key] = [convert(i) for i in value]
return namedtuple('GenericDict', dictionary.keys())(**dictionary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment