Re: Ordered dicts

2006-09-27 Thread bearophileHUGS
Steve Holden: I forgot a detail: in the Python version of Odict I use element deletion is O(n). You need a second dict to improve that (or a duble linked list of hashing operations, see below). > FYI there was a *long* discussion around the need for Speed sprint about > implementing ordered dicts

Re: Ordered dicts

2006-09-26 Thread Steve Holden
[EMAIL PROTECTED] wrote: > I have found that in certain situations ordered dicts are useful. I use > an Odict class written in Python by ROwen that I have improved and > updated some for personal use. > > So I'm thinking about a possible C version of Odict (maybe fit for the > collections module).

Re: Ordered dicts

2006-09-26 Thread Duncan Booth
[EMAIL PROTECTED] wrote: >> Then if you reinsert the deleted value it goes back in at its >> original order. > > Uhm, this doesn't sound good. Thank you, I missed this detail :-) > Then the doubly-linked list, and the links fixing seem necessary... > An alternative to a doubly linked list might

Re: Ordered dicts

2006-09-26 Thread bearophileHUGS
Thank to Neil Cerutti and Duncan Booth for the answers. I have not tried that C AVL implementation yet. Duncan Booth: > but for your ordered dictionary if you did that you would have > to fix up the linked list. To fix the list in constant time you probably need a doubly-linked list, this requir

Re: Ordered dicts

2006-09-26 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > Deleted keys from a dict/set aren't removed, they are tagged as > deleted. > My experience of CPython sources is tiny, I have just read few parts, > so a person much more expert than me can comment the following lines. > > During the printing of the set/dict I think suc

Re: Ordered dicts

2006-09-26 Thread Neil Cerutti
On 2006-09-26, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I have found that in certain situations ordered dicts are > useful. I use an Odict class written in Python by ROwen that I > have improved and updated some for personal use. > > So I'm thinking about a possible C version of Odict (maybe

Re: "Ordered" dicts

2005-08-11 Thread Colin J. Williams
Delaney, Timothy (Tim) wrote: > Martin Miller wrote: > > >>To avoid continued reinvention of this wheel, I'd also vote to have >>this functionality be at least included in a standard module, if not >>built-in. > > > This has been discussed on python-dev (I proposed it actually). The > final con

RE: "Ordered" dicts

2005-08-10 Thread Delaney, Timothy (Tim)
Martin Miller wrote: > To avoid continued reinvention of this wheel, I'd also vote to have > this functionality be at least included in a standard module, if not > built-in. This has been discussed on python-dev (I proposed it actually). The final consensus was that no such implementation would b

Re: "Ordered" dicts

2005-08-10 Thread gene tani
More ways to do it, from the FAQ http://www.python.org/doc/faq/programming.html#how-can-i-get-a-dictionary-to-display-its-keys-in-a-consistent-order Also look at the recipe, page 222 of Cookbook2, that allows you to rank key values by their associated values, and demonstrate the power of mixins.

Re: "Ordered" dicts

2005-08-10 Thread Scott David Daniels
Simon Brunning wrote: > On 8/10/05, Chris Cioffi <[EMAIL PROTECTED]> wrote: > >>I have lots of code that looks like: >>keys = mydict.keys() >>keys.sort() > > > keys = sorted(mydict.keys()) > Or (often useful to get at contents): items = sorted(mydict.items()) as in: For k

Re: "Ordered" dicts

2005-08-10 Thread Martin Miller
[EMAIL PROTECTED] wrote: > > Lots and lots of people want ordered dicts it seems. Or at least, they > > want > > to be able to access their dictionary keys in order. > > [snipped lots of examples, nice pro-con lists, etc.] > > What do y'all think? > > I'll second the need for this. Although, what

Re: "Ordered" dicts

2005-08-10 Thread Simon Brunning
On 8/10/05, Chris Cioffi <[EMAIL PROTECTED]> wrote: > While the sorted() built in addressed (yet another) community desire, I > don't think this addresses the underlying expectation of getting dictionary > keys in some order. You do get them in *some* order. ;-) > It works, but it feel like a

Re: "Ordered" dicts

2005-08-10 Thread Chris Cioffi
On 10/08/05, Simon Brunning <[EMAIL PROTECTED]> wrote: On 8/10/05, Chris Cioffi <[EMAIL PROTECTED]> wrote: > I have lots of code that looks like:> keys = mydict.keys()> keys.sort()keys = sorted(mydict.keys())   While the sorted() built in addressed (yet another) community desire, I don't th

Re: "Ordered" dicts

2005-08-10 Thread Simon Brunning
On 8/10/05, Chris Cioffi <[EMAIL PROTECTED]> wrote: > I have lots of code that looks like: > keys = mydict.keys() > keys.sort() keys = sorted(mydict.keys()) -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/pyt

Re: "Ordered" dicts

2005-08-10 Thread mekstran
> Lots and lots of people want ordered dicts it seems. Or at least, they > want > to be able to access their dictionary keys in order. > [snipped lots of examples, nice pro-con lists, etc.] > What do y'all think? I'll second the need for this. Although, what can also be useful as a further extens