Re: An ordered dictionary for the Python library?

2007-09-15 Thread Diez B. Roggisch
Mark Summerfield schrieb: On 14 Sep, 21:23, James Stroud [EMAIL PROTECTED] wrote: Mark Summerfield wrote: I guess I'll have to rename my module (although unfortunately, my book has just gone into production and I have a (simpler) example of what I considered to be an ordered dict, so I will

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Mark Summerfield
On 14 Sep, 02:35, Jürgen Urner [EMAIL PROTECTED] wrote: Puh, what a discussion... most common use case I can think of is d = {'a': 1, 'b': 2, 'c': 3} for key in d: # do something that relies on order of keys as specified in the constructor It's a bit tireing having to type for

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Mark Summerfield
I forgot one item in the proposed API: ordereddict.delete(index : int) Also, the API for keys() should be ordereddict.keys(firstindex : int = None, secondindex : int = None) If called with no args, returns list of all keys (in key order of course); if one arg is given, returns keys with

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Antoon Pardon
On 2007-09-14, Mark Summerfield [EMAIL PROTECTED] wrote: On 14 Sep, 02:35, Jürgen Urner [EMAIL PROTECTED] wrote: Puh, what a discussion... most common use case I can think of is d = {'a': 1, 'b': 2, 'c': 3} for key in d: # do something that relies on order of keys as specified in the

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Mark Summerfield
On 14 Sep, 10:49, Antoon Pardon [EMAIL PROTECTED] wrote: On 2007-09-14, Mark Summerfield [EMAIL PROTECTED] wrote: On 14 Sep, 02:35, Jürgen Urner [EMAIL PROTECTED] wrote: Puh, what a discussion... most common use case I can think of is d = {'a': 1, 'b': 2, 'c': 3} for key in d:

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Antoon Pardon
On 2007-09-14, Mark Summerfield [EMAIL PROTECTED] wrote: On 14 Sep, 10:49, Antoon Pardon [EMAIL PROTECTED] wrote: # some time later d[e] = 15 # later still d[b] = 70 d.keys() # returns ['a', 'b', 'e', 'm', 'x'] d.values() # returns [1, 70, 15, 4, 20] which seems to be exactly what

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Mark Summerfield
On 14 Sep, 12:46, Antoon Pardon [EMAIL PROTECTED] wrote: On 2007-09-14, Mark Summerfield [EMAIL PROTECTED] wrote: On 14 Sep, 10:49, Antoon Pardon [EMAIL PROTECTED] wrote: # some time later d[e] = 15 # later still d[b] = 70 d.keys() # returns ['a', 'b', 'e', 'm', 'x']

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Antoon Pardon
On 2007-09-14, Mark Summerfield [EMAIL PROTECTED] wrote: Also, it does not provide the key(), value(), and item() methods that the API I proposed can support (because in an ordereddict, index positions make sense). At the time I wrote my module I never had a need for these. Do you have a

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Mark Summerfield
On 14 Sep, 15:35, Antoon Pardon [EMAIL PROTECTED] wrote: [snip] I wish you all the luck you can get. Maybe if you succeed I'll change my mind about writing a PEP myself. However I think your chances will increase if you write your module and have it available in the cheese shop. If people

Re: An ordered dictionary for the Python library?

2007-09-14 Thread James Stroud
Mark Summerfield wrote: So to clarify, here's the entire API I'm proposing for ordereddict. In all cases the ordereddict is always in (and kept in) key order, and any method that returns a list or iterator always returns that list or iterator (whether of keys or values) in key order:

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Mark Summerfield
On 14 Sep, 20:25, James Stroud [EMAIL PROTECTED] wrote: Mark Summerfield wrote: [snip] May I also make one more suggestion, to call it a sort_ordered_dict (or sortordereddict, or even better a sorteddict--where the ed comes from ordered)? Its hard for me to move past the established

Re: An ordered dictionary for the Python library?

2007-09-14 Thread James Stroud
Mark Summerfield wrote: I guess I'll have to rename my module (although unfortunately, my book has just gone into production and I have a (simpler) example of what I considered to be an ordered dict, so I will be adding to the terminology confusion). That notwithstanding, given that it is a

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Mark Summerfield
On 14 Sep, 21:23, James Stroud [EMAIL PROTECTED] wrote: Mark Summerfield wrote: I guess I'll have to rename my module (although unfortunately, my book has just gone into production and I have a (simpler) example of what I considered to be an ordered dict, so I will be adding to the

Re: An ordered dictionary for the Python library?

2007-09-14 Thread Carl Banks
On Thu, 13 Sep 2007 19:21:08 -0700, James Stroud wrote: Carl Banks wrote: On Sep 13, 4:20 pm, James Stroud [EMAIL PROTECTED] wrote: Mark Summerfield wrote: - If an item is inserted it is put in the right place (because the underlying data structure, b*tree, skiplist or whatever is

Re: An ordered dictionary for the Python library?

2007-09-13 Thread Mark Summerfield
On 13 Sep, 00:03, Paul Rubin http://[EMAIL PROTECTED] wrote: Mark Summerfield [EMAIL PROTECTED] writes: I feel that Python lacks one useful data structure: an ordered dictionary. Do other Python programmers feel this lack? Is this worth a PEP? Yes. It should use a functional data

Re: An ordered dictionary for the Python library?

2007-09-13 Thread Antoon Pardon
On 2007-09-12, Mark Summerfield [EMAIL PROTECTED] wrote: On 12 Sep, 13:46, Michele Simionato [EMAIL PROTECTED] wrote: On Sep 12, 2:42 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Wed, 12 Sep 2007 07:33:45 +, Mark Summerfield wrote: In fact, I'm not sure what

Re: An ordered dictionary for the Python library?

2007-09-13 Thread [EMAIL PROTECTED]
On Sep 13, 1:27 am, Mark Summerfield [EMAIL PROTECTED] wrote: On 13 Sep, 00:03, Paul Rubin http://[EMAIL PROTECTED] wrote: Mark Summerfield [EMAIL PROTECTED] writes: I feel that Python lacks one useful data structure: an ordered dictionary. Do other Python programmers feel this lack?

Re: An ordered dictionary for the Python library?

2007-09-13 Thread James Stroud
Mark Summerfield wrote: - If an item is inserted it is put in the right place (because the underlying data structure, b*tree, skiplist or whatever is intrinsically ordered by on the key) +1 for all your suggestions below, but -1 for the above. You suggest that myOrderedDict['key'] = value

Re: An ordered dictionary for the Python library?

2007-09-13 Thread Paul Rubin
Mark Summerfield [EMAIL PROTECTED] writes: Yes. It should use a functional data structure. Could you elaborate? I mean use a data structure like an AVL tree, that can make a new dict object quickly, whose contents are the same as the old object except for one element (i.e. most of the

Re: An ordered dictionary for the Python library?

2007-09-13 Thread James Stroud
James Stroud wrote: set_value_at - set_value (not simply set) Actually, 'set' seems better than set_value. -- http://mail.python.org/mailman/listinfo/python-list

Re: An ordered dictionary for the Python library?

2007-09-13 Thread Carl Banks
On Sep 13, 4:20 pm, James Stroud [EMAIL PROTECTED] wrote: Mark Summerfield wrote: - If an item is inserted it is put in the right place (because the underlying data structure, b*tree, skiplist or whatever is intrinsically ordered by on the key) +1 for all your suggestions below, but -1

Re: An ordered dictionary for the Python library?

2007-09-13 Thread Jürgen Urner
Puh, what a discussion... most common use case I can think of is d = {'a': 1, 'b': 2, 'c': 3} for key in d: # do something that relies on order of keys as specified in the constructor It's a bit tireing having to type for key in sorted(d.keys()): do_somethig_with(d[key])

Re: An ordered dictionary for the Python library?

2007-09-13 Thread James Stroud
Carl Banks wrote: On Sep 13, 4:20 pm, James Stroud [EMAIL PROTECTED] wrote: Mark Summerfield wrote: - If an item is inserted it is put in the right place (because the underlying data structure, b*tree, skiplist or whatever is intrinsically ordered by on the key) +1 for all your suggestions

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Michele Simionato
On Sep 12, 9:33 am, Mark Summerfield [EMAIL PROTECTED] wrote: I feel that Python lacks one useful data structure: an ordered dictionary. I find such data structures v. useful in C++. I know that in Python the sort function is v. fast, but often I prefer never to sort but simply to use an

Re: An ordered dictionary for the Python library?

2007-09-12 Thread stef
Mark Summerfield wrote: I feel that Python lacks one useful data structure: an ordered dictionary. I find such data structures v. useful in C++. I know that in Python the sort function is v. fast, but often I prefer never to sort but simply to use an ordered data structure in the first

Re: An ordered dictionary for the Python library?

2007-09-12 Thread thebjorn
On Sep 12, 9:33 am, Mark Summerfield [EMAIL PROTECTED] wrote: I feel that Python lacks one useful data structure: an ordered dictionary. I find such data structures v. useful in C++. I know that in Python the sort function is v. fast, but often I prefer never to sort but simply to use an

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Steven D'Aprano
On Wed, 12 Sep 2007 07:33:45 +, Mark Summerfield wrote: I feel that Python lacks one useful data structure: an ordered dictionary. I find such data structures v. useful in C++. [snip] Personally, I've never missed an ordered dict. What do people use them for? In fact, I'm not sure

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Michele Simionato
On Sep 12, 2:42 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Wed, 12 Sep 2007 07:33:45 +, Mark Summerfield wrote: In fact, I'm not sure what people mean by ordered dicts. I assume they mean the keys are ordered, not the values. But ordered by what? Insertion order?

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Steven D'Aprano
On Wed, 12 Sep 2007 09:51:02 +0200, stef wrote: If you're going to extend the dictionary, there's one other flag I'm continuously missing: case-insensitive key. Completely untested and probably buggy as anything, but here's an absolutely minimal case-insensitive dictionary. class

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Mark Summerfield
On 12 Sep, 13:46, Michele Simionato [EMAIL PROTECTED] wrote: On Sep 12, 2:42 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Wed, 12 Sep 2007 07:33:45 +, Mark Summerfield wrote: In fact, I'm not sure what people mean by ordered dicts. I assume they mean the keys are

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Michele Simionato
On Sep 12, 3:54 pm, Mark Summerfield [EMAIL PROTECTED] wrote: On 12 Sep, 13:46, Michele Simionato [EMAIL PROTECTED] Actually I meant by key order, so insertion order doesn't matter at all. If you need a dictionary-like data structure that respects insertion order you could use a list of (key,

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Duncan Booth
Steven D'Aprano [EMAIL PROTECTED] wrote: In fact, I'm not sure what people mean by ordered dicts. I assume they mean the keys are ordered, not the values. But ordered by what? Insertion order? Modification order? Alphabetical order? All of the above at different times. Usually I think they

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Roel Schroeven
Michele Simionato schreef: On Sep 12, 2:42 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Wed, 12 Sep 2007 07:33:45 +, Mark Summerfield wrote: In fact, I'm not sure what people mean by ordered dicts. I assume they mean the keys are ordered, not the values. But ordered

RE: An ordered dictionary for the Python library?

2007-09-12 Thread Hamilton, William
From: Michele Simionato On Sep 12, 3:54 pm, Mark Summerfield [EMAIL PROTECTED] wrote: On 12 Sep, 13:46, Michele Simionato [EMAIL PROTECTED] Actually I meant by key order, so insertion order doesn't matter at all. If you need a dictionary-like data structure that respects insertion

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Chris Mellon
On 9/12/07, Mark Summerfield [EMAIL PROTECTED] wrote: On 12 Sep, 13:46, Michele Simionato [EMAIL PROTECTED] wrote: On Sep 12, 2:42 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Wed, 12 Sep 2007 07:33:45 +, Mark Summerfield wrote: In fact, I'm not sure what

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Carl Banks
On Sep 12, 10:04 am, Michele Simionato [EMAIL PROTECTED] wrote: On Sep 12, 3:54 pm, Mark Summerfield [EMAIL PROTECTED] wrote: On 12 Sep, 13:46, Michele Simionato [EMAIL PROTECTED] Actually I meant by key order, so insertion order doesn't matter at all. If you need a dictionary-like

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Carl Banks
On Sep 12, 8:42 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Wed, 12 Sep 2007 07:33:45 +, Mark Summerfield wrote: I feel that Python lacks one useful data structure: an ordered dictionary. I find such data structures v. useful in C++. [snip] Personally, I've

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Neil Cerutti
On 2007-09-12, Mark Summerfield [EMAIL PROTECTED] wrote: Actually I meant by key order, so insertion order doesn't matter at all. If you need a dictionary-like data structure that respects insertion order you could use a list of (key, value) tuples. Another respondent asked about use cases.

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Mark Summerfield
On 12 Sep, 15:04, Michele Simionato [EMAIL PROTECTED] wrote: On Sep 12, 3:54 pm, Mark Summerfield [EMAIL PROTECTED] wrote: On 12 Sep, 13:46, Michele Simionato [EMAIL PROTECTED] Actually I meant by key order, so insertion order doesn't matter at all. If you need a dictionary-like data

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Russell E. Owen
In article [EMAIL PROTECTED], Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 12 Sep 2007 07:33:45 +, Mark Summerfield wrote: I feel that Python lacks one useful data structure: an ordered dictionary. I find such data structures v. useful in C++. [snip] Personally, I've

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Tuomas
Mark Summerfield wrote: I feel that Python lacks one useful data structure: an ordered dictionary. Why it should be a dict. With it you can only maintain the order x1x2x3... But by definition the order only requires x1=x2=x3... There are many use cases where keys are not unique. I'd prefer a

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Paul Rubin
Mark Summerfield [EMAIL PROTECTED] writes: I feel that Python lacks one useful data structure: an ordered dictionary. Do other Python programmers feel this lack? Is this worth a PEP? Yes. It should use a functional data structure. -- http://mail.python.org/mailman/listinfo/python-list