def dedupe_list_of_dicts(ld):
def _freeze(o):<EOL><INDENT>"""<STR_LIT>"""<EOL>if isinstance(o, dict):<EOL><INDENT>return frozenset((k, _freeze(v)) for k, v in six.iteritems(o))<EOL><DEDENT>elif isinstance(o, (list, tuple)):<EOL><INDENT>return tuple(_freeze(v) for v in o)<EOL><DEDENT>else:<EOL><INDENT>return o<EOL><DEDENT><DEDENT>result = []<EOL>seen = set()<EOL>for d in ld:<EOL><INDENT>f = _freeze(d)<EOL>if f not in seen:<EOL><INDENT>result.append(d)<EOL>seen.add(f)<EOL><DEDENT><DEDENT>return result<EOL>
Remove duplicates from a list of dictionaries preserving the order.

    We can't use the generic list helper because a dictionary isn't hashable.
    Adapted from http://stackoverflow.com/a/9427216/374865.