python bijection
M.-A. Lemburg
mal at egenix.com
Thu Dec 3 07:04:48 EST 2009
Raymond Hettinger wrote:
> [Joshua Bronson]
>> Raymond, do you think there might be any future in including a built-
>> in bidict data structure in Python?
>
> I don't think so. There are several forces working against it:
>
> * the recipe is new, so it hasn't had a chance to mature
> or to gain a fan club.
>
> * there are many approaches to the solving the problem and
> there is no reason to assume this one is the best.
>
> * it extends the language with arcane syntax tricks instead of
> using the language as designed by Guido. That makes it harder
> to learn and remember.
>
> * we've already got one (actually two). The two dictionary approach
> uses plain python, requires no new learning, and is more flexible.
> Also, sqlite3 provides another way to use multiple lookups to a
> single record. The database approach is much more general
> (extending to trijections, allowing multiple sort orders,
> providing persistence, etc).
>
> * the semantics of a bijection aren't obvious:
>
> b['x'] = 'ex' # first record: ('x', 'ex')
> b['y'] = 'why' # second record: ('y', 'why')
> b[:'why'] = 'x' # do two records collapse into one? is there
> an error?
>
> * the proposed syntax doesn't address the issue covered in my previous
> post.
> Since bijections are symmetrical, they do not have an obvious
> direction
> (which is the primary key, the husband or the wife?). The syntax
> needs to
> allow user names to make it clear which is being accessed:
>
> marriages.h2w['john'] = 'amy'
> marriages.w2h['amy'] = 'john'
>
> Contrast this with:
>
> marriages['jordan'] = 'taylor' # are you sure you got the
> order correct?
> marriages[:'taylor'] = 'jordan' # this is easy to get backwards
I think the only major CS data type missing from Python is some
form of (fast) directed graph implementation à la kjGraph:
http://gadfly.sourceforge.net/kjbuckets.html
With these, you can easily build all sorts of relations between
objects and apply fast operations on them. In fact, it should then
be possible to build a complete relational database in Python
(along the lines of Gadfly).
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Dec 03 2009)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-list
mailing list