Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93896
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Mapping, with sequence as key, wildcard and subsequence matching |
| Date | 2015-07-16 01:27 -0400 |
| References | <85k2u0vpis.fsf@benfinney.id.au> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.556.1437024480.3674.python-list@python.org> (permalink) |
On 7/15/2015 9:51 PM, Ben Finney wrote:
> Howdy all,
>
> What well-defined data type exists with the following properties:
>
> * Mapping, key → value.
>
> * Each key is a sequence (e.g. `tuple`) of items such as text strings.
>
> * Items in a key may be the sentinel `ANY` value, which will match any
> value at that position.
>
> * A key may specify that it will match *only* sequences of the same
> length.
>
> * A key may specify that it will match sequences with arbitrarily many
> additional unspecified items.
Every key should signal which of the last two alterntives holds. One can
be a default. The signal can be 'in-band', in the tuple key itself, or
'out-of-band', not in the tuple key. An in-band signal must be a
special value, like 'ANY', that is not otherwise used in keys. ...
might be a good choice. For out-of-band, you could try a tuple subclass
with a __new__ method that sets an attribute. Or wrap a tuple, say with
a list, to signal the non-default alternative. Something like
tail = False
if type(key) is list:
tail = True
key = key.pop()
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Mapping, with sequence as key, wildcard and subsequence matching Terry Reedy <tjreedy@udel.edu> - 2015-07-16 01:27 -0400
csiph-web