Set of Dictionary

Scott David Daniels Scott.Daniels at Acm.Org
Thu Jun 16 11:18:48 EDT 2005

Vibha Tripathi wrote:
> Hi Folks,
> I know sets have been implemented using dictionary but
> I absolutely need to have a set of dictionaries...any
> ideas how to do that?
> Peace.
> Vibha
> "Things are only impossible until they are not."
> __________________________________ 
> Discover Yahoo! 
> Find restaurants, movies, travel and more fun for the weekend. Check it out! 
This is too bad.  There is a problem even defining what you want.

Assume we have a DictSet type:

      a = dict(a=1, b=2)
      b = dict(a=2, b=1)
      c = dict(b=2, a=1)
      ds = Dictset([a, b, c])
What is len(ds)?

After those lines and:
     c['a'] = 2
What is len(ds)?

After all the previous lines and:
     a['a'] = 2
     b['b'] = 2
What is len(ds)?

Making sets of mutable things is pretty useless.
You could make sets of tuple(sorted(adict.items()))
if the "adict"s don't have mutable values.

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list