Mapping, with sequence as key, wildcard and subsequence matching
breamoreboy at yahoo.co.uk
Thu Jul 16 09:24:08 CEST 2015
On 16/07/2015 08:09, Mark Lawrence wrote:
> On 16/07/2015 07:37, Ben Finney wrote:
>> Ethan Furman <ethan at stoneleaf.us> writes:
>>> On 07/15/2015 10:53 PM, Ben Finney wrote:
>>>> Are those the ‘__contains__’, ‘__getitem__’ methods? What actually
>>>> is the API of a mapping type, that would need to be customised for
>>>> this application?
>>> The problem is that potential key matches are found by hashes
>> For the Python ‘dict’ type, yes. I already know that I don't want that
>> type, I want a custom mapping type which matches keys according to the
>> algorithm I specify.
>> So, I'm not asking “how do I make ‘dict’ do this?”. I am instead asking
>> “how do I implement a custom type which can duck-type for ‘dict’ but
>> have a different key-lookup implementation?”.
> The collections module provides a MutableMapping abstract base class to
> help create those methods from a base set of __getitem__(),
> __setitem__(), __delitem__(), and keys()
> Hunting for examples got me to
> so fingers crossed, I'm just hoping that we're going in the right
Drat, should have scrolled down one more page on the activestate recipe,
Stephen D'Aprano comment.
This is very ingenious, but I wouldn't want to touch it with a ten foot
pole for production code
Eric Snow replied.
Oh yeah. I wouldn't use it in production either. :) I expect you could
iron out the wrinkles, but there are better solutions.
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
More information about the Python-list