[New-bugs-announce] [issue16385] evaluating dict with repeated keys gives no error/warnings

Albert Ferras report at bugs.python.org
Fri Nov 2 13:27:47 CET 2012


New submission from Albert Ferras:

I normally use dictionaries for configuration purposes in python, but there's a problem where I have a dictionary with many key<->values and one of the keys is repeated.
For example:

lives_in = { 'lion': ['Africa', 'America],
             'parrot': ['Europe'],
             #... 100+ more rows here
             'lion': ['Europe'],
             #... 100+ more rows here
           }

will end up with animal_lives_in['lion'] = 'Europe'. There's no way to detect that I've written a mistake in the code because python won't tell me there's a duplicated key assigned. It's easy to see when you have few keys but hard when you've got many.

I think it should atleast raise a warning when this happens.

----------
components: Interpreter Core
messages: 174507
nosy: Albert.Ferras
priority: normal
severity: normal
status: open
title: evaluating dict with repeated keys gives no error/warnings
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16385>
_______________________________________


More information about the New-bugs-announce mailing list