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

MRAB python at mrabarnett.plus.com
Tue Jun 16 23:56:39 CEST 2009


spir wrote:
> Le Tue, 16 Jun 2009 18:46:21 +0100,
> MRAB <python at mrabarnett.plus.com> s'exprima ainsi:
> 
>> How about ['a':'1', 'b':'2', 'c':'3']?
> (for ordered dict literal)
> 
> I really find this sensible.
> We have then:
> * [a, b, c] & [k1:v1, k2:v2, k3:v3] for ordered containers
> * {a, b, c} & {k1:v1, k2:v2, k3:v3} for unordered ones
> 
> +1.0 for me
> 
> Update: confusion of 1-item ordered dict with slice? Or just the same as confusion of 1-item list with index? (Note: have always found that [] and [:] for index and slice was somewhat wrong).
> 
Can you confuse a 1-item list with an index? No, because the
syntax/grammar disambiguates them. Is that also the case with a 1-item
ordered dict vs a slice? In Python 2.6, [0 : 1] (== slice(0, 1)) raises
SyntaxError. Does that also occur in Python 3.x?



More information about the Python-ideas mailing list