Jim Jewett wrote:
> On 5/2/06, Raymond Hettinger <[EMAIL PROTECTED]> 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
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com