PEP 218 Re: ANN: set-0.1 module available

Denis S. Otkidach ods at fep.ru
Fri May 17 08:48:15 EDT 2002


On Fri, 17 May 2002, James J. Besemer wrote:

JJB> You could further argue that we must have a immutable form
JJB> of SETs,
JJB> so they could serve as dictionary indices.  What's the
JJB> argument for
JJB> having a mutable form, other than tuple has it?  Let alone
JJB> both?

We often need a collection that is extended step-by-step avoiding
duplicates.  Certainly we can use immutable sets:

s = {-}
for item in some_sequence:
    if is_good(item):
        s &= {item}  # create new set if it's immutable or just
                     # add otherwise

but such code will be too expensive for large sets.

If we write similar code for strings we'll use StringIO (consider
it's some kind of mutable string) or intermidiate list (and join
items afterwards).  Collecting in list is OK with sets too if we
don't need intermediate results as sets.  But what about StringIO
equivalent for sets?  Other immutable types are not agregates
(except complex numbers, but this is a special case) and we need
not mutable form for them.






More information about the Python-list mailing list