Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'expressions': 0.07; 'patterns.': 0.07; 'type,': 0.07; 'api': 0.09; 'dict': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '8bit%:32': 0.16; 'defer': 0.16; 'expression.': 0.16; 'keys.': 0.16; 'mapping,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Mapping': 0.16; 'subject:key': 0.16; 'unresolved': 0.16; 'tests.': 0.18; 'otherwise,': 0.20; '(you': 0.23; 'matching': 0.23; 'header:User- Agent:1': 0.26; '(which': 0.26; 'header:X-Complaints-To:1': 0.26; 'sequence': 0.27; 'regular': 0.29; 'behaviour': 0.29; 'equality': 0.29; 'hash': 0.29; 'strings,': 0.29; 'that.': 0.30; 'candidate': 0.31; "can't": 0.32; "d'aprano": 0.33; 'steven': 0.33; 'values.': 0.33; 'case,': 0.34; 'mapping': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'received:org': 0.37; 'requirement': 0.37; 'skip:z 10': 0.38; 'thank': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'your': 0.60; 'engine': 0.62; 'great': 0.63; 'world': 0.64; 'you.': 0.64; 'due': 0.65; 'us:': 0.67; 'us,': 0.69; 'skip:\xe2 10': 0.70; 'theoretical': 0.72; 'special': 0.73; 'sounds': 0.76; '_o__)': 0.84; 'application?': 0.84; 'insight,': 0.84; 'received:125': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Mapping, with sequence as key, wildcard and subsequence matching Date: Thu, 16 Jul 2015 15:53:21 +1000 References: <55a72c8b$0$1671$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:39MAxvmHXrBxawvhTsfC5mReO5Y= 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437026017 news.xs4all.nl 2916 [2001:888:2000:d::a6]:38811 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.91.MISMATCH!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:93897 Steven D'Aprano writes: > Sounds like a regular expression. Remember that computer science > theoretical regular expressions don't just match strings, they can > apply to any sequence of primitive values. Good insight, thank you. > In your case, you only need two special tokens, match-one and > match-one-or-more (which may be like r'.' and r'.*'). It actually needs “one” and “zero-or-more”. Which does match your analogous regex ‘.’ and ‘.*’ patterns. > Otherwise, you can create your own sequence type and simple regex > engine (you only need two meta-items, [ONE and ZERO-OR-MORE]) to > perform equality tests. It may have to come to that. That's not such a problem, but: > You can't use a dict for the mapping, not unless you're smarter than > me, due to the requirement to hash the keys. Dang. It's the mapping that I really need to solve, I think. A mapping that has a custom “does this candidate match any existing key” and “return the value for this key” to defer to the matching behaviour described above. Are those the ‘__contains__’, ‘__getitem__’ methods? What actually is the API of a mapping type, that would need to be customised for this application? -- \ “If we listen only to those who are like us, we will squander | `\ the great opportunity before us: To live together peacefully in | _o__) a world of unresolved differences.” —David Weinberger | Ben Finney