Re: Custom dict to prevent keys from being overridden

2011-08-27 Thread Steven D'Aprano
Julien wrote: > What I'd like to achieve is: > d = { > ... 'a': 1, > ... 'b': 2, > ... 'a': 3 > ... } > Error: The key 'a' already exists. > > Is that possible, and if so, how? Not if the requirements including using built-in dicts { }. But if you are happy enough to use a custom cl

Custom dict to prevent keys from being overridden

2011-08-27 Thread Julien
Hi, With a simple dict, the following happens: >>> d = { ... 'a': 1, ... 'b': 2, ... 'a': 3 ... } >>> d {'a': 3, 'b': 2} ... i.e. the value for the 'a' key gets overridden. What I'd like to achieve is: >>> d = { ... 'a': 1, ... 'b': 2, ... 'a': 3 ... } Error: The key 'a' already ex