Skip to content

Instantly share code, notes, and snippets.

@href
Created October 27, 2011 12:00
Show Gist options
  • Save href/1319371 to your computer and use it in GitHub Desktop.
Save href/1319371 to your computer and use it in GitHub Desktop.

Revisions

  1. href revised this gist Oct 28, 2011. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion dict_namedtuple.py
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,13 @@
    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
    True
    """
  2. href revised this gist Oct 28, 2011. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion dict_namedtuple.py
    Original file line number Diff line number Diff line change
    @@ -1 +1,12 @@
    namedtuple('GenericDict', dictionary.keys())(**dictionary)
    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
  3. href created this gist Oct 27, 2011.
    1 change: 1 addition & 0 deletions dict_namedtuple.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    namedtuple('GenericDict', dictionary.keys())(**dictionary)