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


Groups > comp.lang.python > #93902

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'test,': 0.05; 'implements': 0.07; 'linear': 0.07; 'type,': 0.07; 'api': 0.09; 'check.': 0.09; 'decision.': 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; 'release,': 0.09; 'targets': 0.09; 'tuple': 0.09; '(but': 0.15; 'properly': 0.15; 'first)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sequential': 0.16; 'subject:Mapping': 0.16; 'subject:key': 0.16; 'utterly': 0.16; 'retrieval': 0.18; 'do.': 0.22; 'keys': 0.22; "python's": 0.23; 'implemented': 0.24; 'testing': 0.25; "i've": 0.25; 'header:User- Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'chris': 0.26; 'fine': 0.28; 'hash': 0.29; 'key,': 0.29; 'lies': 0.29; "i'm": 0.30; 'code': 0.30; "i'd": 0.31; 'error.': 0.31; 'probably': 0.31; "can't": 0.32; 'case,': 0.34; 'membership': 0.34; 'mapping': 0.35; 'item': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'turn': 0.37; 'received:org': 0.37; 'suggestion': 0.37; 'seem': 0.37; 'means': 0.39; 'why': 0.39; 'sure': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'per': 0.62; 'matter': 0.63; 'virtually': 0.66; 'talking': 0.67; 'discover': 0.73; 'honest': 0.76; 'truth': 0.79; 'trial': 0.81; '_o__)': 0.84; 'concept,': 0.84; 'generations,': 0.84; 'received:125': 0.84; 'ultimately,': 0.84; 'items,': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Mapping, with sequence as key, wildcard and subsequence matching
Date Thu, 16 Jul 2015 16:31:50 +1000
References <85k2u0vpis.fsf@benfinney.id.au> <mo7fco$tme$1@ger.gmane.org> <85bnfcve7w.fsf@benfinney.id.au> <CAPTjJmrNVFcT5O9H3EtiSa1rthjkLP2+hdVcRciTr9gmnmD7LA@mail.gmail.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 <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
Cancel-Lock sha1:ikLiihOUo3FoOoRdGrxswTUNkaE=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.562.1437028318.3674.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1437028318 news.xs4all.nl 2875 [2001:888:2000:d::a6]:51094
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:93902

Show key headers only | View raw


Chris Angelico <rosuav@gmail.com> writes:

> I'm not sure you really need a mapping type per se.

My reasons include (but I can probably think of more) testing membership
via the ‘key in mapping’ syntax.

> with the "match any" concept, there's actually a potential for
> ambiguities, which means you need a sequential (strictest first)
> check. In any case, it's virtually impossible to hash a tuple of
> strings such that it can match multiple targets, based only on what
> the targets do.

I'm fine with not having the keys hashed, so long as I can use the
mapping API (membership test, item retrieval by key, rejecting keys that
already match one of the items, etc.).

In other words, I'm not limiting myself to Python's ‘dict’ type, which
is why I've only been talking about a type which can be classified as a
mapping type.

> Steven's suggestion to turn this into an honest linear search is
> probably what I'd do; ultimately, a dict that can't hash its keys
> properly is going to devolve to that anyway.

Fine by me. What is the mapping API that needs to be implemented though?

I can guess, but for code I intend to release, API design should not be
a matter of guessing. I'd rather have an already-worked example of a
custom mapping type that fully implements the API used by Python's
mapping type, without having to discover it all by trial and error. Once
this is out in the wild, I don't want to discover I made a bad API
design decision.

-- 
 \       “When a well-packaged web of lies has been sold to the masses |
  `\    over generations, the truth will seem utterly preposterous and |
_o__)                    its speaker a raving lunatic.” —Dresden James |
Ben Finney

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


Thread

Re: Mapping, with sequence as key, wildcard and subsequence matching Ben Finney <ben+python@benfinney.id.au> - 2015-07-16 16:31 +1000

csiph-web