[Python-3000] A few small py3k wishes
Ian Bicking
ianb at colorstudy.com
Mon Apr 3 22:15:59 CEST 2006
adam deprince wrote:
> On 4/3/06, Ian Bicking <ianb at colorstudy.com> wrote:
> [snip]
>
>>Adam gave one possible implementation. Another would be a keyed
>>dictionary, e.g.,: KeyedDict(key=lambda s: s.lower()). A keyed
>>dictionary would internally call that function on keys to get the "true"
>>key, but things like .keys() would return the keys that were passed in.
>
>
> I'm sorry, I should have been more clear. My "implementation," if
> you can even call it that, was intended as a counter-example to
> Talin's suggestion.
>
> Talin's concern was addressed long ago with the ability to subclass
> built in types. Its easy to flavor a dict to act however you want.
> My point wasn't "look how easy this is, lets add it to the core
> language" but rather "look how easy the core language makes it for you
> to do this yourself."
>
> IMHO, if you want a flavor of dict, extend it yourself. Case
> insensitivity has no place in the core language.
I think a keyed dictionary is just as useful a case as defaultdict,
though like defaultdict I don't think it needs to be part of dict
itself. I strongly favor a greater number of collection patterns being
in the standard library, including things like bags and multidicts and
ordered dictionaries and all that. People are reinventing these things
all the time, with varying levels of robustness, performance, and
different APIs. For example, many people implement case insensitive
dictionaries with key normalization, but I think the keyed form is
generally better (though less obvious).
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Python-3000
mailing list