[Python-ideas] Sets, Dictionaries
Nick Coghlan
ncoghlan at gmail.com
Fri Mar 30 01:27:20 EDT 2018
On 30 March 2018 at 02:04, Clint Hepner <clint.hepner at gmail.com> wrote:
>
>> On 2018 Mar 29 , at 11:42 a, Julia Kim <julia.hiyeon.kim at gmail.com> wrote:
>>
>> My suggestion is to change the syntax for creating an empty set and an empty dictionary as following.
>>
>> an_empty_set = {}
>> an_empty_dictionary = {:}
>
> If you are willing to accept {:} as an empty dict, then surely {,} would suffice as an empty set, with no backwards compatibility issues at all.
>
> Also, this is also not a new idea (https://mail.python.org/pipermail/python-3000/2006-April/001286.html). I don't know
> if this was never seriously considered further, or if it was formally rejected.
I believe the main concern is that where "set()" is easy to look up in
documentation, "{,}" isn't all that obvious (and isn't easy to search
for), so folks would have to learn it by rote.
It would also lead to the question of "If {,} is allowed for empty
sets, why don't we allow (,) for empty tuples, and [,] for empty
lists?".
That said, a case could potentially be made for "Disambiguating empty
container notation" that allowed all four options:
* Unambiguous empty dict: {:}
* Syntactic empty set: {,}
* Empty tuple with optional comma: (,)
* Empty list with optional comma: [,]
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list