[Python-ideas] syntax for set
Ron Adam
rrr at ronadam.com
Mon Nov 22 17:49:15 CET 2010
On 11/22/2010 04:16 AM, Jan Kaliszewski wrote:
> Terry Reedy dixit (2010-11-15, 13:45):
>
>> The *only* glitch is the lack of an empty set notation. The idea of
>> dict() == {:}; set()=={};
>> which would be the obvious choice if starting fresh,
>> was considered but rejected by Guido as too disruptive
>> and introducing another barrier between Python 2 and 3.
>
> I'd be happy with:
>
> * {:} for empty dict() (as a collection of key-value *pairs*)
> * {.} for empty set() (as a similar collection of *single* elements)
>
> And {} for empty dict() as well -- to keep compatibility (maybe to be
> deprecated later).
Maybe it's not intentional, but where ever a colon is used, it tends to
mean "make an association to". (except in slicing)
Key : value # This is also name : object.
class name : class body
function name : function body
And where ever a '.' is, it tends to mean "get a sub-part of:
class name . method name
So the {.} doesn't really fit with this idea. Probably the correct set
notation would have been {} if it was put into python before dictionaries.
If you follow this line of reasoning, then a dictionary is a set of
associations. ie... {} for set, and : for associated to, and put those
together and we have {:}.
An interesting "wild" idea might be to delay defining weather it's a
dictionary or a set depending on how it's first used. Then {} could be
both an empty set and an empty dictionary, but I think there are probably
are a lot of reasons not to do that.
Ron
More information about the Python-ideas
mailing list