Re: python bijection

2009-11-28 Thread Joshua Bronson
On Nov 27, 9:36 pm, "Gabriel Genellina" wrote: > En Fri, 27 Nov 2009 15:12:36 -0300, Francis Carr   > escribió: > > > I was really inspired by this discussion thread! :-) > > > After much tinkering, I think I have a simpler solution.  Just make > > the inverse mapping accessible via an attribute,

Re: python bijection

2009-12-01 Thread Joshua Bronson
On Nov 27, 1:12 pm, Francis Carr wrote: > I was really inspired by this discussion thread! :-) > > After much tinkering, I think I have a simpler solution.  Just make > the inverse mapping accessible via an attribute, -AND- bind the > inverse of -THAT- mapping back to the original.  The result is

Re: python bijection

2009-12-01 Thread Joshua Bronson
On Dec 1, 2:11 pm, 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 recip

Re: python bijection

2009-12-02 Thread Joshua Bronson
On Dec 1, 8:17 pm, a...@pythoncraft.com (Aahz) wrote: > In article > <85100df7-a8b0-47e9-a854-ba8a8a2f3...@r31g2000vbi.googlegroups.com>, > Joshua Bronson   wrote: > >I noticed the phonebook example in your ActiveState recipe and thought > >you might consider ch

Re: python bijection

2009-12-02 Thread Joshua Bronson
On Dec 1, 9:03 pm, Chris Rebert wrote: > Reminds me of this quite funny blog post: > "Gay marriage: the database engineering perspective" > http://qntm.org/?gay amazing -- http://mail.python.org/mailman/listinfo/python-list

heapq._siftdown / decrease-key support?

2010-01-13 Thread Joshua Bronson
I recently implemented A* search in Python using the heapq module and in my first pass, to accomplish the decrease-key operation I resorted to doing a linear scan of the list to find the position of the key in the heap, and then calling the private undocumented method heapq._siftdown at this positi

Re: heapq._siftdown / decrease-key support?

2010-01-14 Thread Joshua Bronson
Thanks for the responses! On Thu, Jan 14, 2010 at 12:23 AM, Daniel Stutzbach wrote: > Your guess is correct. Someday I'd like to rewrite HeapDict in C for speed, > but I haven't been able to find the time (and no one has offered to pay me to > make the time ;) ). Daniel, did you realize you c

Re: heapq._siftdown / decrease-key support?

2010-01-18 Thread Joshua Bronson
On Sun, Jan 17, 2010 at 11:30 PM, Raymond Hettinger wrote: > > > Raymond, do you think this technique is worth documenting in the heapq > > module? It'd be too bad if any future users incorrectly think that it > > won't meet their needs the way I did. > > Yes.  Please assign a tracker issue to me

python bijection

2009-11-20 Thread Joshua Bronson
I couldn't find a library providing a bijective map data structure (allowing for constant-time lookups by value) in the few minutes I looked, so I took a few more minutes to code one up: http://bitbucket.org/jab/toys/src/tip/bijection.py Is this at all worth releasing? Comments and suggestions wel

Re: python bijection

2009-11-20 Thread Joshua Bronson
On Nov 19, 7:05 pm, Steven D'Aprano wrote: > If I want a mapping a <-> b, I generally just create a dict {a:b, b:a}. > What is the advantages or disadvantages of your code over the simplicity > of the dict approach? Well for one, you don't have to manually update the mapping from b -> a if ever t

Re: python bijection

2009-11-20 Thread Joshua Bronson
On Nov 19, 9:17 pm, Carl Banks wrote: > Apart from the GPL what Ben said :) > it seems perfectly fine to release, and looks like > an interesting strategy. I've wanted one of those once in a while, > never enough to bother looking for one or writing one myself. glad to hear it! i'll release it

Re: python bijection

2009-11-20 Thread Joshua Bronson
On Nov 20, 3:09 pm, Terry Reedy wrote: > Joshua Bronson wrote: > > Anyone have any other feedback? For instance, is offering the __call__ > > syntax for the inverse mapping wonderful or terrible, or maybe both? > > Terrible ;-) > > Use standard subscripting with slices,

Re: python bijection

2009-11-20 Thread Joshua Bronson
On Nov 20, 3:09 pm, Terry Reedy wrote: > Use standard subscripting with slices, and only that, to both get and set. i did this for __delitem__ too, so you can do e.g. del m[:'abc']. > In fact, to emphasize the symmetry of the bijective map, consider > disallowing m[key] as ambiguous and require

Re: python bijection

2009-11-24 Thread Joshua Bronson
Hey Raymond, Thanks for your thoughtful reply! I think your idea for a class- generation approach in the spirit of namedtuple is brilliant; looking forward to coding this up and seeing how it feels to use it. (By the way, it occurred to me that "bijection" is perhaps the wrong term to use for thi

Re: python bijection

2009-11-24 Thread Joshua Bronson
On Nov 24, 6:49 pm, Gregory Ewing wrote: > Joshua Bronson wrote: > > So I'm > > thinking of renaming the class injectivedict or idict instead of > > bijection. Is that crazy?) > > I think you'd be better off calling it something more > down-to-earth

Re: python bijection

2009-11-26 Thread Joshua Bronson
On Nov 24, 10:28 pm, Joshua Bronson wrote: > bidict it is! now available at http://bitbucket.org/jab/toys/src/tip/bidict.py and now featuring new shiny namedbidict goodness! as always, feedback welcome. josh -- http://mail.python.org/mailman/listinfo/python-list

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Joshua Bronson
On Jul 22, 7:55 am, Duncan Booth wrote: > I find it interesting that the heapq functions tell you in the > documentation that they aren't suitable for use where n==1 or where n is > near the total size of the sequence whereas random.sample() chooses what it > thinks is the best algorithm based on

heapq "key" arguments

2009-07-31 Thread Joshua Bronson
According to http://docs.python.org/library/heapq.html, Python 2.5 added an optional "key" argument to heapq.nsmallest and heapq.nlargest. I could never understand why they didn't also add a "key" argument to the other relevant functions (heapify, heappush, etc). Say I want to maintain a heap of (x

Re: heapq "key" arguments

2009-07-31 Thread Joshua Bronson
On Jul 31, 2:02 pm, Jonathan Gardner wrote: > On Jul 31, 10:44 am, Joshua Bronson wrote: > > > Say I want to maintain a heap of (x, y) pairs sorted only by > > first coordinate. Without being able to pass key=itemgetter(0), won't > > heapifying a list of such pai

Re: heapq "key" arguments

2009-08-06 Thread Joshua Bronson
On Aug 3, 1:36 pm, Raymond Hettinger wrote: > [Joshua Bronson]: > > > According tohttp://docs.python.org/library/heapq.html, Python 2.5 > > added an optional "key" argument to heapq.nsmallest and > > heapq.nlargest. I could never understand why they didn'

New Tkinter windows don't get focus on OS X

2009-09-09 Thread Joshua Bronson
If you try something like: $ python -m Tkinter -c 'Tkinter._test()' in Terminal on OS X, you'll notice that the window that is spawned does not get focus, rather focus remains in Terminal. Furthermore, if you hit Command+Tab to switch focus to the Python process, you'll notice that for some reaso

Re: New Tkinter windows don't get focus on OS X

2009-09-10 Thread Joshua Bronson
Hey Kevin, Thanks for your quick reply. On Sep 10, 10:12 am, Kevin Walzer wrote: > On 9/10/09 1:27 AM, Joshua Bronson wrote: > > If you try something like: > > > $ python -m Tkinter -c 'Tkinter._test()' > > > in Terminal on OS X, you'll notice that t

Re: New Tkinter windows don't get focus on OS X

2009-09-14 Thread Joshua Bronson
On Sep 11, 3:53 am, eb303 wrote: > For the OP: the problem comes from the tcl/tk level. Running a tcl > script just opening a window from the terminal shows the same > behaviour. You might want to forward the question to the tcl guys. Done: https://sourceforge.net/mailarchive/forum.php?thread_nam