Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.031 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.05; 'matches': 0.07; 'type,': 0.07; 'api': 0.09; 'collections': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; '8bit%:32': 0.16; 'foot': 0.16; 'hashes': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Mapping': 0.16; 'subject:key': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'language': 0.19; '>>>': 0.20; 'algorithm': 0.20; 'either.': 0.22; 'keys': 0.22; 'lawrence': 0.22; 'stephen': 0.22; 'examples': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'url:activestate': 0.29; "i'm": 0.30; "we're": 0.30; 'code': 0.30; 'solutions.': 0.30; 'skip:_ 10': 0.32; 'implement': 0.32; 'language.': 0.32; 'class': 0.33; 'problem': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'url:code': 0.34; 'so,': 0.35; 'could': 0.35; 'eric': 0.35; 'mapping': 0.35; 'asking': 0.35; 'according': 0.36; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'there': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'mark': 0.40; 'subject:with': 0.40; 'ten': 0.60; 'url:3': 0.60; 'more': 0.63; 'different': 0.63; 'our': 0.64; 'iron': 0.66; 'touch': 0.66; 'production': 0.67; 'skip:\xe2 10': 0.70; 'hoping': 0.77; '8bit%:16': 0.84; 'application?': 0.84; 'pole': 0.84; 'pythonistas,': 0.84; 'url:datamodel': 0.84; 'url:recipes': 0.84; 'comment.': 0.91; 'ethan': 0.91; 'furman': 0.91; 'replied.': 0.91; 'snow': 0.91; 'url:reference': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Mapping, with sequence as key, wildcard and subsequence matching Date: Thu, 16 Jul 2015 08:24:08 +0100 References: <55a72c8b$0$1671$c3e8da3$5496439d@news.astraweb.com> <85fv4oveb2.fsf@benfinney.id.au> <55A74FAC.4090807@stoneleaf.us> <85y4igtxoh.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: host-92-22-86-251.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437031467 news.xs4all.nl 2842 [2001:888:2000:d::a6]:45967 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 5652 X-Received-Body-CRC: 1647743042 Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:93909 On 16/07/2015 08:09, Mark Lawrence wrote: > On 16/07/2015 07:37, Ben Finney wrote: >> Ethan Furman 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 > > > > The collections module provides a MutableMapping abstract base class to > help create those methods from a base set of __getitem__(), > __setitem__(), __delitem__(), and keys() > > > 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. > 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. Mark Lawrence