[Python-ideas] dictionary constructor should not allow duplicate keys

Ethan Furman ethan at stoneleaf.us
Wed May 4 12:09:22 EDT 2016


On 05/04/2016 07:20 AM, Steven D'Aprano wrote:
> On Wed, May 04, 2016 at 02:03:59PM +1000, Nick Coghlan wrote:

> This has been the documented behaviour of dicts since at least 1.5:
>
> https://docs.python.org/release/1.5/ref/ref-7.html#HEADING7-35
>
> and it matches the behaviour of both the dict constructor and dict
> comprehensions.

Okay, we had dict displays and dicts, and now you say dict 
constructor... do you mean dict()?  Because:

   >>> dict(a=1, a=1)
     File "<stdin>", line 1
   SyntaxError: keyword argument repeated

is certainly not allowing duplicates.

--
~Ethan~


More information about the Python-ideas mailing list