PEP 218 Re: ANN: set-0.1 module available

Delaney, Timothy tdelaney at avaya.com
Mon May 20 21:49:45 EDT 2002


> From: Roman Suzi [mailto:rnd at onego.ru]
> 
> - mutable sets are more practical. If one needs to use set as 
> a dict key,
> let him convert it to sorted tuple and do so. I think, it's a 
> rare case.
> Much more rare than need to append element to the set.

This is exactly what I was going to say, but Roman beat me to it.

s = {-}
d = {}
s |= 1
s |= 2
t = tuple(s)
d[t] = s

For this to work, the following things would need to be true.

1. For the sets s1 and s2, if s1 == s2, tuple(s1) == tuple(s2) must be true.

2. For this to work, set.__iter__ must return an iterator which returns
items in a guaranteed order. It would not be sufficient to return the items
of a sorted list - then you have the problem of instances of two different
classes that compare equal but are sorted in arbitrary order. However, in
order for s1 to equal s2, we must already have a guaranteed order for the
comparison, so this should be trivial.

Tim Delaney





More information about the Python-list mailing list