Set of Dictionary

Vibha Tripathi vibtrip at yahoo.com
Thu Jun 16 18:09:59 CEST 2005


I need sets as sets in mathematics:
   sets of any unique type of objects including those
of dictionaries, I should then be able to do:
a_set.__contains__(a_dictionary) and things like that.


Can sets in Python 2.4.1, be reimplemented from
scratch to not have it work on top of dict?

Peace.
Vibha


--- Konstantin Veretennicov <kveretennicov at gmail.com>
wrote:

> On 6/16/05, Vibha Tripathi <vibtrip at yahoo.com>
> wrote:
> > Hi Folks,
> > 
> > I know sets have been implemented using dictionary
> but
> > I absolutely need to have a set of dictionaries...
> 
> While you can't have a set of mutable objects (even
> dictionaries :)),
> you can have a set of immutable snapshots of those
> objects:
> 
> >>> d1 = {1: 'a', 2: 'b'}
> >>> d2 = {3: 'c'}
> >>> s = set([tuple(d1.iteritems()),
> tuple(d2.iteritems())])
> >>> s
> set([((3, 'c'),), ((1, 'a'), (2, 'b'))])
> >>> [dict(pairs) for pairs in s]
> [{3: 'c'}, {1: 'a', 2: 'b'}]
> 
> - kv
> 


=======
"Things are only impossible until they are not."

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Python-list mailing list