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


Groups > comp.lang.python > #93897

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

From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Mapping, with sequence as key, wildcard and subsequence matching
Date 2015-07-16 15:53 +1000
References <mailman.552.1437011478.3674.python-list@python.org> <55a72c8b$0$1671$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.557.1437026017.3674.python-list@python.org> (permalink)

Show all headers | View raw


Steven D'Aprano <steve@pearwood.info> 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

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