[Python-3000] sets in P3K?

Guido van Rossum guido at python.org
Thu May 4 01:20:53 CEST 2006


I suspect Raymond has plenty of good reasons to shoot this one down.

I'll add a few more: what's the union of {1:1} and {1:2}? The
intersection? The difference? Refuse the temptation to guess!

--Guido

On 5/3/06, Delaney, Timothy (Tim) <tdelaney at avaya.com> wrote:
> Jim Jewett wrote:
>
> > On 5/2/06, Raymond Hettinger <rhettinger at ewtllc.com> wrote:
> >
> >> I think Guido had the best solution.  Use set() for empty sets, use
> >> {} for empty dicts, use {genexp} for set comprehensions/displays, use
> >> {1,2,3} for explicit set literals, and use {k1:v1, k2:v2} for dict
> >> literals.  We can always add {/} later if demand exceeds distaste.
> >
> > I understand {1,2,3} vs {k1:v1, k2:v2}, but what is the {genexp} for?
>
> Hmm - how about a slightly radical solution (which I think came up when
> we were first discussing introducing sets ...).
>
> Do away with sets altogether. Make the syntax {1, 2, 3} syntactic sugar
> for {1:None, 2:None, 3:None}.
>
> Pros:
>
> 1. No ambiguity concerning {}.
>
> 2. {genexp} will always produce a dict. However, there would be some
> ambiguity if we wanted to support single-value-producing genexps (i.e.
> returning a single value rather than a 2-tuple for each element). Simple
> to disallow that, and provide a wrapper generator that takes an iterable
> of single-value elements and generates 2-tuples.
>
> Cons:
>
> 1. The set/dict operations don't completely overlap.
>
> 2. Performance for set-like dicts won't be as good as for builtin sets.
>
> Tim Delaney
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>


--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list