Convert a list of dictionaries into a set of dictionaries
<p>How can i make a set of dictionaries from one list of dictionaries?</p>

<p>Example:</p>

<pre><code>import copy

v1 = {'k01': 'v01', 'k02': {'k03': 'v03', 'k04': {'k05': 'v05'}}}
v2 = {'k11': 'v11', 'k12': {'k13': 'v13', 'k14': {'k15': 'v15'}}}

data = []
N = 5
for i in range(N):
    data.append(copy.deepcopy(v1))
    data.append(copy.deepcopy(v2))

print data
</code></pre>

<p>How would you create a set of dictionaries from the list <code>data</code>?</p>

<p>NS: One dictionary is equal to another when they are structurally the same. That means, they got <strong>exactly</strong> the same keys and same values (recursively) </p>

<p>Dictionaries are mutable and therefore not hashable in python.</p>

<p>You could either create a dict-subclass with a <code>__hash__</code> method. Make sure that the hash of a dictionary does not change while it is in the set (that probably means that you cannot allow modifying the members).
See <a href="http://code.activestate.com/recipes/414283-frozen-dictionaries/" rel="nofollow">http://code.activestate.com/recipes/414283-frozen-dictionaries/</a> for an example implementation of frozendicts.</p>

<p>If you can define a sort order on your (frozen) dictionaries, you could alternatively use a data structure based on a binary tree instead of a set. This boils down to the bisect solution provided in the link below.</p>

<p>See also <a href="http://stackoverflow.com/a/18824158/5069869">http://stackoverflow.com/a/18824158/5069869</a> for an explanation why sets without hash do not make sense.</p>

python dictionary