PEP 218 Re: ANN: set-0.1 module available

Roman Suzi rnd at onego.ru
Fri May 17 09:13:16 EDT 2002


On Fri, 17 May 2002, Denis S. Otkidach wrote:

> 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

I think, that is

s = set(filter(is_good, some_sequence))

is for.

> 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.

I hope for mutable sets so. I even think, sets could use 
a generalised member function:

N in Integers

f in SecureFunctions

where membership function is substituted. So, set built-in type is more
about setting a protocol for set type. At first, implementation doesn't
matter much.

I see sets as constracts similar to lists but with automatic duplicate
exclusion and as efficient as possible lookup. And also with irrelevant
order of elements. And it doesn't matter if they will be implemented as
bit fields (for integers and chars), hashes or lists/dicts under the
cover. Protocol will be their to change implementation later.

And I hope those who know what set is, is also aware of the costs of the
set operations.

Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
 






More information about the Python-list mailing list