Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93906

Re: Mapping, with sequence as key, wildcard and subsequence matching

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Mapping, with sequence as key, wildcard and subsequence matching
Date 2015-07-16 08:09 +0100
References <mailman.552.1437011478.3674.python-list@python.org> <55a72c8b$0$1671$c3e8da3$5496439d@news.astraweb.com> <85fv4oveb2.fsf@benfinney.id.au> <55A74FAC.4090807@stoneleaf.us> <85y4igtxoh.fsf@benfinney.id.au>
Newsgroups comp.lang.python
Message-ID <mailman.565.1437030570.3674.python-list@python.org> (permalink)

Show all headers | View raw


On 16/07/2015 07:37, Ben Finney wrote:
> Ethan Furman <ethan@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?”.
>

https://docs.python.org/3/reference/datamodel.html?emulating-container-types 


<quote>
The collections module provides a MutableMapping abstract base class to 
help create those methods from a base set of __getitem__(), 
__setitem__(), __delitem__(), and keys()
</quote>

Hence 
https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableMapping

Hunting for examples got me to 
http://code.activestate.com/recipes/578096-a-mutablemapping-that-can-use-unhashable-objects-a/ 
so fingers crossed, I'm just hoping that we're going in the right direction.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Mapping, with sequence as key, wildcard and subsequence matching Ben Finney <ben+python@benfinney.id.au> - 2015-07-16 11:51 +1000
  Re: Mapping, with sequence as key, wildcard and subsequence matching Steven D'Aprano <steve@pearwood.info> - 2015-07-16 14:01 +1000
    Re: Mapping, with sequence as key, wildcard and subsequence matching Ben Finney <ben+python@benfinney.id.au> - 2015-07-16 15:53 +1000
    Re: Mapping, with sequence as key, wildcard and subsequence matching Ethan Furman <ethan@stoneleaf.us> - 2015-07-15 23:31 -0700
    Re: Mapping, with sequence as key, wildcard and subsequence matching Ben Finney <ben+python@benfinney.id.au> - 2015-07-16 16:37 +1000
    Re: Mapping, with sequence as key, wildcard and subsequence matching Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-16 08:09 +0100
    Re: Mapping, with sequence as key, wildcard and subsequence matching Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-16 08:24 +0100
  Re: Mapping, with sequence as key, wildcard and subsequence matching Marko Rauhamaa <marko@pacujo.net> - 2015-07-16 09:53 +0300

csiph-web