def freeze(o):
    """
    Freezes any mutable object including dictionaries and lists for hashing.
    Accepts nested dictionaries.
    """
    if isinstance(o, (tuple, list)):
        return tuple(sorted(freeze(e) for e in o))

    if isinstance(o, dict):
        return tuple(sorted((k, freeze(v)) for k, v in iteritems(o)))

    if isinstance(o, (set, frozenset)):
        return tuple(sorted(freeze(e) for e in o))

    return o
def freeze ( o ) : if isinstance ( o , ( tuple , list ) ) : return tuple ( sorted ( freeze ( e ) for e in o ) ) if isinstance ( o , dict ) : return tuple ( sorted ( ( k , freeze ( v ) ) for k , v in iteritems ( o ) ) ) if isinstance ( o , ( set , frozenset ) ) : return tuple ( sorted ( freeze ( e ) for e in o ) ) return o
Freezes any mutable object including dictionaries and lists for hashing.
    Accepts nested dictionaries.