def dict2tuple(mydict):
result = []<EOL>for key in mydict.keys():<EOL><INDENT>try:<EOL><INDENT>keys = mydict[key].keys()<EOL>key_result = dict2tuple(mydict[key])<EOL><DEDENT>except AttributeError:<EOL><INDENT>if type(mydict[key]) == type([]):<EOL><INDENT>key_result = []<EOL>for elt in mydict[key]:<EOL><INDENT>key_result.append(dict2tuple(elt))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>key_result = mydict[key]<EOL><DEDENT><DEDENT>result.append((key, key_result))<EOL><DEDENT>return tuple(result)<EOL>
Turn a dictionary of the form used by DINGO
(i.e., a key is mapped to either another dictionary,
a list or a value) into a tuple-representation.
This is useful for providing a standard python object that
observes the order of elements (which standard dictionaries don't).