[Tutor] Sets

Norvell Spearman norvell@houseofspearman.org
Fri Apr 18 03:58:02 2003

On Thursday, 2003.04.17, 19:23:47 -0700, Sean 'Shaleh' Perry wrote:
> On Thursday 17 April 2003 17:32, Brian Christopher Robinson wrote:
> > I think I read that sets will be a primitive data type in the next version
> > of Python, but what is a good way to implement them now?
> use a dictionary.

Not that I know a better implementation (I'm new to Python and only
recently began studying set theory), but why is using a dictionary a
good way to implement sets?  According to the set theory text I'm using
(and this is the text's notation, not Python code):

    (1) {a, a} = {a}
    (2) {a, b} = {b, a}

Since dictionaries are unordered (2) above is covered, but wouldn't (1)
(if one creates a set class using a dictionary) require a method to get
rid of---or ignore---duplicates?  Or would one implement a set where the
dictionary's key:value pairs are item:frequency and two sets are equal
if their respective dictionaries contain the same items, ignoring 
frequencies > 0?  Would the null set then be represented by

    my_set = {}

Or am I using ``sets'' in the wrong context?

Thanks for any answers.

Norvell Spearman