[NN] >> uniques_map = {} >> for d in list_of_dicts: >> uniques[dict_hash(d)] = d >> unique_dicts = uniques_map.values()
[Dave Angel] > unique_dicts = [] > for d in list_of_dicts: > if d not in unique_dicts: > unique_dicts.append(d) > > Do it, then decide if performance is inadequate. Only then should you > worry about faster methods, especially if the faster method is broken. Another variant: # keys and values in the dictionaries must be hashable list_of_dicts = ... unique_dicts_map = {} for d in list_of_dicts: key = frozenset(d.items()) unique_dicts_map[key] = d unique_dicts = unique_dicts_map.values() I'm using a frozenset because it is hashable. It should be easy to see that two dicts are equal if and only if they comprise a set of equal key-value pairs. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor