Mapping, with sequence as key, wildcard and subsequence matching

2015-07-15 Thread Ben Finney
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

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

2015-07-15 Thread Steven D'Aprano
On Thu, 16 Jul 2015 11:51 am, 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

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

2015-07-15 Thread Terry Reedy
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 a

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

2015-07-15 Thread Ben Finney
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 >

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

2015-07-15 Thread Ben Finney
Terry Reedy writes: > On 7/15/2015 9:51 PM, Ben Finney wrote: > > 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` val

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

2015-07-15 Thread Chris Angelico
On Thu, Jul 16, 2015 at 3:55 PM, Ben Finney wrote: > Thanks. The part which puzzle me though: How do we teach the mapping > type about that matching behaviour? I'm not sure you really need a mapping type per se. The benefit of something like Python's dict is that it gives really fast lookups via

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

2015-07-15 Thread Ethan Furman
On 07/15/2015 10:53 PM, Ben Finney wrote: Steven D'Aprano writes: 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 m

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

2015-07-15 Thread Ben Finney
Chris Angelico 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 sequentia

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

2015-07-15 Thread Ben Finney
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 F

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

2015-07-15 Thread Zachary Ware
On Thu, Jul 16, 2015 at 1:31 AM, Ben Finney wrote: > Fine by me. What is the mapping API that needs to be implemented though? Have a look at collections.MutableMapping. -- Zach -- https://mail.python.org/mailman/listinfo/python-list

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

2015-07-15 Thread Marko Rauhamaa
Ben Finney : > 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

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

2015-07-16 Thread Mark Lawrence
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 mat

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

2015-07-16 Thread Ben Finney
Zachary Ware writes: > On Thu, Jul 16, 2015 at 1:31 AM, Ben Finney > wrote: > > Fine by me. What is the mapping API that needs to be implemented though? > > Have a look at collections.MutableMapping. Thank you, that's great! I hadn't realised the ‘collections’ module had such comprehensive cov

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

2015-07-16 Thread Mark Lawrence
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 applicati

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

2015-07-16 Thread Mark Lawrence
On 16/07/2015 08:11, Ben Finney wrote: Zachary Ware writes: On Thu, Jul 16, 2015 at 1:31 AM, Ben Finney wrote: Fine by me. What is the mapping API that needs to be implemented though? Have a look at collections.MutableMapping. Thank you, that's great! I hadn't realised the ‘collections’

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

2015-07-16 Thread Laura Creighton
I'm ill, so I am not trusting my own reasoning further than I can jump (not too far today) but I don't think you have a problem that is well-suited to a mapping. But it seems like a perfect fit for a tree, to me. Laura -- https://mail.python.org/mailman/listinfo/python-list