[Python-ideas] [Python-Dev] hello, new dict addition for new eve ?
dreamingforward at gmail.com
Fri Dec 30 23:00:14 CET 2011
On Fri, Dec 30, 2011 at 2:01 PM, Nathan Schneider <nathan at cmu.edu> wrote:
> On Fri, Dec 30, 2011 at 2:37 PM, Bruce Leban <bruce at leapyear.org> wrote:
>> On Fri, Dec 30, 2011 at 9:12 AM, Eric Snow <ericsnowcurrently at gmail.com>
>>> On Fri, Dec 30, 2011 at 10:02 AM, Guido van Rossum <guido at python.org>
>>> > What I meant is similar to set union on the keys, where if a key exists
>>> > in
>>> > both dicts, the value in the result is equal to one of the values in the
>>> > operands (and if the value is the same for both operands, that value is
>>> > also
>>> > the result value).
Far more powerful is to allow an optional "collision" function that is
called *only* when a key collision occurs. Special case the default
behavior so that little performance hit is made if no such function is
given upon initialization. Add the functionality to defaultdict and
see if it gets more traction.
I think you'll find a lot of code can be refactored with this simple
abstraction. It becomes trivial and canonical to create a graph class
for example (at least in implementation if not in interface.) To add
that feature to the interface, you need to refactor the set/dict
relationship so that dict inherits from set. Then you'll really
cooking with gas....
More information about the Python-ideas