Why aren't colons optional?

Alex Martelli aleax at aleax.it
Sun Jan 20 16:54:56 EST 2002


Neil Hodgson wrote:

> Alex Martelli:
> 
>> The use of {} for dictionary-displays is indeed a tiny anomaly (but I
>> have no better idea for the general case; for the reasonably common case
>> where keys are constant identifiers, of course,
> 
>    Is ['a':1, 'b':2, 'c':3] not feasible? It looks easy to disambiguate
>    from
> [1, 2, 3] lists although it would introduce a new 'mixing list and
> dictionary notation' error for [1, 'a':1]. Doesn't look like it would be
> ambiguous with slicing as the contexts are different.

Not technically ambiguous for the parser, perhaps, as long as a
stand-alone 1:3 or [1:3] is not accepted as meaning a range iterator (I
recall such a PEP being rejected once, but hope dies slowly:-).  But
having the meaning of [1:3] so highly context-dependent does not
appeal all that much to me (although in that it wouldn't differ from
present [7] -- either singleton list or indexing operation).


Alex




More information about the Python-list mailing list