Skip to content

Instantly share code, notes, and snippets.

@micaleel
Forked from href/dict_namedtuple.py
Last active August 29, 2015 14:23
Show Gist options
  • Save micaleel/c19356de0904e1edd061 to your computer and use it in GitHub Desktop.
Save micaleel/c19356de0904e1edd061 to your computer and use it in GitHub Desktop.
from collections import namedtuple
def convert(dictionary):
return namedtuple('GenericDict', dictionary.keys())(**dictionary)
"""
>>> d = dictionary(a=1, b='b', c=[3])
>>> named = convert(d)
>>> named.a == d.a
True
>>> named.b == d.b
True
>>> named.c == d.c
True
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment