[Python-ideas] Possible method of distinguishing between set-literals, dict-literals, and odict-literals

MRAB python at mrabarnett.plus.com
Tue Jun 16 19:46:21 CEST 2009


Ron Adam wrote:
> 
> 
> Ben Finney wrote:
>> Carl Johnson
>> <cmjohnson.mailinglist at gmail.com> writes:
>>
>>> we could introduce an empty set-literal and an odict-literal, and add
>>> a more explicit form to replace the existing set literal.
>>
>> What do you mean by “more explicit”? The existing set literal syntax
>> is quite explicit.
>>
>>> s{} could be the empty set, o{} could be an empty odict, and we could
>>> leave {} alone as the form for dicts. So, an odict literal would look
>>> like o{'a':'1', 'b':'2', 'c':'3'} instead of OrderedDict([('a', '1'),
>>> ('b', '2'), ('c', '3')]). And the set {'a', 'c', 'b'} could
>>> (optionally?) have a little s{'a', 'c', 'b'} to make it more explicit
>>> that this is a set, not a dict.
>>
>> I don't think that word “explicit” means what you think it means.
> 
> I think Carl is thinking that it is more concise and easier to read.
> 
> When you read OrderedDict([('a', '1'),('b', '2'), ('c', '3')]),  your 
> mind is parsing  *Ordered Dictionary from list of these three tuples*.
> 
> Whebn you read *o{'a':'1', 'b':'2', 'c':'3'}*, your mind does not have 
> the extra noise of converting the argument list of the constructor.
> 
How about ['a':'1', 'b':'2', 'c':'3']?

> 
> I think it really depends on how often ordered dictionaries literals 
> will be used weather or not it is worth doing.  It also uses about 30% 
> to 50% less keystrokes.
> 
Ideally we would have [...] for ordered and {...} for unordered, with
':' if it's keyed:

     []  ordered,   value      (list)
     [:] ordered,   key+value  (odict)
     {}  unordered, value      (set)
     {:} unordered, key+value  (dict)

It's too late to change that in Python 3.x, so it would have to be:

     []  ordered,   value      (list)
     [:] ordered,   key+value  (odict)
     {,} unordered, value      (set)
     {}  unordered, key+value  (dict)



More information about the Python-ideas mailing list