Re: Why are there no ordered dictionaries?

2005-11-22 Thread Fredrik Lundh
Stuart McGraw wrote What would improve the Cheese Shop's interface for you? Getting rid of those damn top level links to old versions. Seeing a long list of old versions, when 99% of visitors are only interested in the current version, is just visual noise, and really lame. Move the old

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Ben Sizer
Fredrik Lundh wrote: Ben Sizer wrote: This is interesting; I would have thought that the tuple is read and a dictionary created by inserting each pair sequentially. Is this not the case? pointers to the members of each pair, yes. but a pointer copy is a cheap operation (for the given

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Stuart McGraw
Fredrik Lundh [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Stuart McGraw wrote What would improve the Cheese Shop's interface for you? Getting rid of those damn top level links to old versions. Seeing a long list of old versions, when 99% of visitors are only interested

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
to be the primary problem people who complain with why no sprollificator mode? questions. What I don't understand is why legitimate questions such as why are there no ordered dictionaries are immediately interpreted as *complaints* and not just as questions. If I ask such a question, I am

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Fredrik Lundh
Stuart McGraw wrote: Hmm, so two versions means one is a development version, and the other is a stable version? I did not know that, and did not see it documented on the site. I would say documenting that would be an interface improvement. well, that's up to the developer. when you

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On 22 Nov 2005 03:07:47 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: Ok, so if not in the standard library, what is the problem? Can't find what you want with google and PyPI etc.? Or haven't really settled on what your _requirements_ are? That seems to be the

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 10:26:22 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Bengt Richter wrote: d = OrderedDict(); d[1]='one'; d[2]='two' = list(d) = [1, 2] ok, now we do d[1]='ein' and what is the order? list(d) = [2, 1] ?? Or do replacements not count as insertions? If you simply

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
Alex Martelli wrote: Perl's _arrays_ are a bit like Python _lists_, and ordered; it's the _hashes_ that are a bit like Python _dicts_, and unordered. PHP's use of array for both concepts may indeed be a bit confusing. Perl's _hashes_ have been also called _associative arrays_ originally.

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
Fuzzyman schrieb: Of course ours is ordered *and* orderable ! You can explicitly alter the sequence attribute to change the ordering. What I actually wanted to say is that there may be a confusion between a sorted dictionary (one where the keys are automatically sorted) and an ordered

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
Bengt Richter wrote: I'm mostly friendly ;-) I'm pretty sure you are :-) -- Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
Bengt Richter wrote: After finally reading that the odict.py in PyPI by Larosa/Foord was what was desired, but slower in use than what Fredrik posted, I decided to see if I could speed up odict.py. I now have a version that I think may be generally faster. Hm, I wouldn't formulate it that

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Carsten Haese
On Tue, 2005-11-22 at 13:37, Christoph Zwerschke wrote: Would the default semantics below really be that suprising? An ordered dictionary remembers the order in which keys are first seen [...] Overwriting an entry replaces its value, but does not affect its position in the key order.

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Kay Schluehr
Bengt Richter wrote: On Mon, 21 Nov 2005 01:27:22 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: if you restructure the list somewhat d = ( ('pid', ('Employee ID', 'int')), ('name', ('Employee name', 'varchar')), ('sal',

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
One implementation detail that I think needs further consideration is in which way to expose the keys and to mix in list methods for ordered dictionaries. In http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 the keys are exposed via the keys() method which is bad. It should be a

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
Magnus Lycka schrieb: I still believe that the concept of an ordered dictionary (behave like dict, only keep the order of the keys) is intuitive and doesn't give you so much scope for ambiguity. Sure. Others think so too. The problem is that if you and these other people actually write

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
def __init__(self, init_val = ()): dict.__init__(self, init_val) self.sequence = [x[0] for x in init_val] Fuzzyman wrote: But that doesn't allow you to create an ordered dict from another ordered dict. Right; I did not want to present a full implementation, just the relevant

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Carsten Haese
On Tue, 2005-11-22 at 14:37, Christoph Zwerschke wrote: In Foord/Larosa's odict, the keys are exposed as a public member which also seems to be a bad idea (If you alter the sequence list so that it no longer reflects the contents of the dictionary, you have broken your OrderedDict). That

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
Carsten Haese schrieb: I don't think it's intuitive if you can't describe it without contradicting yourself. If the order of the keys really were the order in which they were first seen by the dictionary, deleting and recreating a key should maintain its original position. Admitted that

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
Carsten Haese wrote: That could easily be fixed by making the sequence a managed property whose setter raises a ValueError if you try to set it to something that's not a permutation of what it was. Ok, a managed attribute would be an option. You would allow people to do what they want with

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
I still believe that the concept of an ordered dictionary (behave like dict, only keep the order of the keys) is intuitive and doesn't give you so much scope for ambiguity. But probably I need to work on an implementation to become more clear about possible hidden subtleties. Bengt Richter

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Christoph Zwerschke
d1[0:0] + d1[2:2] == OrderedDict( (1, 11), (3, 13) ) Oops, sorry, that was nonsense again. I meant d1[0:1] + d1[1:2] == OrderedDict( (1, 11), (3, 13) ) Ordered dictionaries could allow slicing and concatenation. Some operations such as concatenation need of course special considerations,

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 21:24:29 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Carsten Haese wrote: That could easily be fixed by making the sequence a managed property whose setter raises a ValueError if you try to set it to something that's not a permutation of what it was. Ok, a

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 20:15:18 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: def __init__(self, init_val = ()): dict.__init__(self, init_val) self.sequence = [x[0] for x in init_val] Fuzzyman wrote: But that doesn't allow you to create an ordered dict from another ordered

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On 22 Nov 2005 11:18:19 -0800, Kay Schluehr [EMAIL PROTECTED] wrote: Bengt Richter wrote: On Mon, 21 Nov 2005 01:27:22 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Note that is isn't hard to snap a few pieces together to make an ordered dict to your own specs. But IMO it belongs in

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Bengt Richter wrote: On 22 Nov 2005 03:07:47 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: Ok, so if not in the standard library, what is the problem? Can't find what you want with google and PyPI etc.? Or haven't really settled on what your _requirements_ are?

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Tom Anderson
On Tue, 22 Nov 2005, Carsten Haese wrote: On Tue, 2005-11-22 at 14:37, Christoph Zwerschke wrote: In Foord/Larosa's odict, the keys are exposed as a public member which also seems to be a bad idea (If you alter the sequence list so that it no longer reflects the contents of the dictionary,

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 20:37:40 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: One implementation detail that I think needs further consideration is in which way to expose the keys and to mix in list methods for ordered dictionaries. In

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Tom Anderson
On Tue, 22 Nov 2005, Christoph Zwerschke wrote: One implementation detail that I think needs further consideration is in which way to expose the keys and to mix in list methods for ordered dictionaries. In Foord/Larosa's odict, the keys are exposed as a public member which also seems to

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Tom Anderson
On Tue, 22 Nov 2005, Christoph Zwerschke wrote: Fuzzyman schrieb: Of course ours is ordered *and* orderable ! You can explicitly alter the sequence attribute to change the ordering. What I actually wanted to say is that there may be a confusion between a sorted dictionary (one where the

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Alex Martelli
Christoph Zwerschke [EMAIL PROTECTED] wrote: ... * C++ has a Map template in the STL which is ordered (a Sorted Associative Container). Ordered *by comparisons on keys*, NOT by order of insertion -- an utterly and completely different idea. So ordered dictionaries don't seem to be such an

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 22:06:12 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: d1[0:0] + d1[2:2] == OrderedDict( (1, 11), (3, 13) ) Oops, sorry, that was nonsense again. I meant d1[0:1] + d1[1:2] == OrderedDict( (1, 11), (3, 13) ) Ordered dictionaries could allow slicing and concatenation.

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Alex Martelli
Tom Anderson [EMAIL PROTECTED] wrote: ... have a certain order that is preserved). Those who suggested that the sorted function would be helpful probably thought of a sorted dictionary rather than an ordered dictionary. Exactly. Python could also do with a sorted dict, like binary

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Alex Martelli wrote: However, since Christoph himself just misclassified C++'s std::map as ordered (it would be sorted in this new terminology he's now introducing), it seems obvious that the terminological confusion is rife. Many requests and offers in the past for ordered dictionaries

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On 22 Nov 2005 19:15:42 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Alex Martelli wrote: However, since Christoph himself just misclassified C++'s std::map as ordered (it would be sorted in this new terminology he's now introducing), it seems obvious that the terminological confusion is

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Bengt Richter wrote: For me the implication of sorted is that there is a sorting algorithm that can be used to create an ordering from a prior state of order, whereas ordered could be the result of arbitrary permutation, e.g., manual shuffling, etc. Of course either way, a result can be said

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Ganesan Rajagopal
[EMAIL PROTECTED] com [EMAIL PROTECTED] writes: what would be the definition of sorted and ordered, before we can go on ? Sorted would be ordered by key comparison. Iterating over such a container will give you the keys in sorted order. Java calls this a SortedMap. See

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Ganesan Rajagopal
Alex Martelli [EMAIL PROTECTED] writes: Ordered *by order of key insertion*: Java, PHP Ordered *by other criteria*: LISP, C++ Java supports both ordered by key insertion (LinkedHashMap) as well as ordered by key comparison (TreeMap). Ganesan -- Ganesan Rajagopal (rganesan at

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: For me the implication of sorted is that there is a sorting algorithm that can be used to create an ordering from a prior state of order, whereas ordered could be the result of arbitrary permutation, e.g., manual shuffling,

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Alex Martelli wrote: What you can obtain (or anyway easily simulate in terms of effects on a loop) through an explicit call to the 'sorted' built-in, possibly with a suitable 'key=' parameter, I would call sorted -- exactly because, as Bengt put it, there IS a sorting algorithm which, etc,

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... But I can also record these changes in a seperate table which then becomes a sorted case ? somedict['x']='y', per se, does no magic callback to let you record anything when type(somedict) is dict. You can wrap or subclass to your heart's

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Alex Martelli wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... But I can also record these changes in a seperate table which then becomes a sorted case ? somedict['x']='y', per se, does no magic callback to let you record anything when type(somedict) is dict. You can wrap or

Re: Why are there no ordered dictionaries?

2005-11-21 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: but you can easily generate an index when you need it: index = dict(d) name, type = index[pid] print name the index should take less than a microsecond to create, and since it points to

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: If I need the dict feature 90% of the time, and the list feature 10% of the time. Wasn't your use case that you wanted to specify form fields in a given order (LIST), render a default view of the form in that order (LIST), and, later on, access the field specifiers in

Re: Why are there no ordered dictionaries?

2005-11-21 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: If I need the dict feature 90% of the time, and the list feature 10% of the time. Wasn't your use case that you wanted to specify form fields in a given order (LIST), render a default view of the form in that order (LIST), and, later on,

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Antoon Pardon
Op 2005-11-21, Christoph Zwerschke schreef [EMAIL PROTECTED]: [EMAIL PROTECTED] wrote: Personally, I have needs for ordered dict but I don't think it should be in standard library though, as different situation called for different behaviour for ordered and skewing my code to a standard lib

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Ben Sizer
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: Using the same logic, we don't need types other than string in a DBMS as we can always convert a string field into some other types when it is needed. No, that's not the same logic. The dict() in my example doesn't convert be- tween data

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fredrik Lundh
Ben Sizer wrote: No, that's not the same logic. The dict() in my example doesn't convert be- tween data types; it provides a new way to view an existing data structure. This is interesting; I would have thought that the tuple is read and a dictionary created by inserting each pair

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fuzzyman
Fredrik Lundh wrote: Ben Sizer wrote: No, that's not the same logic. The dict() in my example doesn't convert be- tween data types; it provides a new way to view an existing data structure. This is interesting; I would have thought that the tuple is read and a dictionary

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... d = somedict_from_db() prefer=['f','a',b'] def my_order(d): for x in prefer: if x in d: yield x s = frozenset(prefer) for x in d: if x not in s: yield x Yes, a much cleaner architecture (if you don't need any sorting

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fredrik Lundh
Fuzzyman wrote: [snip..] (as an example, on my machine, using Foord's OrderedDict class on Zwerschke's example, creating the dictionary in the first place takes 5 times longer than the index approach, and accessing an item takes 3 times longer. you can in fact recreate the index 6

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Christoph Zwerschke
Ben Finney wrote: Another possibility: ordered dictionaries are not needed when Python 2.4 has the 'sorted' builtin. Christoph Zwerschke wrote: The 'sorted' function does not help in the case I have indicated, where I do not want the keys to be sorted alphabetically, but according to

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Christoph Zwerschke
Fredrik Lundh wrote: (as an example, on my machine, using Foord's OrderedDict class on Zwerschke's example, creating the dictionary in the first place takes 5 times longer than the index approach, and accessing an item takes 3 times longer. you can in fact recreate the index 6 times before

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Alex Martelli
Fredrik Lundh [EMAIL PROTECTED] wrote: ... (but assume that I have some other use case isn't a valid use case) +1 QOTW Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Christoph Zwerschke
Alex Martelli wrote: Note the plural in 'insertion orderS': some people care about the FIRST time a key was added to a dict, some about the LAST time it was added, some about the latest time it was 'first inserted' (added and wasn't already there) as long as it's never been deleted since that

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Aahz
In article [EMAIL PROTECTED], Alex Martelli [EMAIL PROTECTED] wrote: I think you're wrong here. People in the past who have requested or implemented stuff they called 'ordered dicts' in the past had in mind drastically different things, based on some combination of insertion orders, keys, and

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Tom Anderson
On Sun, 20 Nov 2005, Alex Martelli wrote: Christoph Zwerschke [EMAIL PROTECTED] wrote: The 'sorted' function does not help in the case I have indicated, where I do not want the keys to be sorted alphabetically, but according to some criteria which cannot be derived from the keys

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Kay Schluehr
Fredrik Lundh wrote: huh? if you want a list, use a list. d = [('a', {...}), ('b', {})] If one wants uniform access to a nested data structure like this one usually starts writing a wrapper class. I do not think the requirement is anyhow deeper than a standard wrapper around such a

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Christoph Zwerschke
Fredrik Lundh wrote: I'll repeat this one last time: for the use cases presented by Zwerschke and bonono, using a list as the master data structure, and creating the dictionary on demand, is a lot faster than using a ready-made ordered dict implementation. if you will access things via the

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Bengt Richter
On 20 Nov 2005 21:12:52 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: On Sun, 20 Nov 2005 22:03:34 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Ordering the keys isn't the normal case, and can be done easily when needed. That depends. Maybe I do not want

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Bengt Richter
On Mon, 21 Nov 2005 01:27:22 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: if you restructure the list somewhat d = ( ('pid', ('Employee ID', 'int')), ('name', ('Employee name', 'varchar')), ('sal', ('Salary', 'float')) ) you

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Bengt Richter
On 21 Nov 2005 01:54:38 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: If I need the dict feature 90% of the time, and the list feature 10% of the time. Wasn't your use case that you wanted to specify form fields in a given order (LIST),

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Alex Martelli
Christoph Zwerschke [EMAIL PROTECTED] wrote: ... But I think the following rule is natural enough to consider it as THE standard behavior of ordered dictionaries: Insertion: If the key exists: Don't change the order. If it does not exist: Append it to the sequence of keys. Deletion:

Why are there no ordered dictionaries?

2005-11-20 Thread Christoph Zwerschke
This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an ordered dictionary class at least in the standard list? Time and again I am missing that feature. Maybe there is something wrong with my programming style, but I rather

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Ben Finney
Christoph Zwerschke [EMAIL PROTECTED] wrote: This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an ordered dictionary class at least in the standard list? What answers have you received that have not been satisfactory?

Re: Why are there no ordered dictionaries?

2005-11-20 Thread przemek drochomirecki
Uzytkownik Christoph Zwerschke [EMAIL PROTECTED] napisal w wiadomosci news:[EMAIL PROTECTED] This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an ordered dictionary class at least in the standard list? Time and again I am

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
przemek drochomirecki wrote: i am not sure what is the purpose of having ordered dictionaries built in python, could u provide any examples? i use a contruction: for x in sorted(d.keys()) By ordered dict, one usually wants order that is arbitary which cannot be derived from the content,

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: I am writing a web applications(simple forms) which has a number of fields. Each field naturally has a name and a number of attributes(formatting etc.), like this : d = {'a':{...}, 'b':{}} This dict would be passed to the Kid template system which would lay it

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: I am writing a web applications(simple forms) which has a number of fields. Each field naturally has a name and a number of attributes(formatting etc.), like this : d = {'a':{...}, 'b':{}} This dict would be passed to the Kid

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Nicola Larosa
You asked why not rather than has anyone done this anyway; if you asked the latter of the Python Cookbook, you might find something like this: URL:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 A little old, and pre-dates subclassable native types, but quite

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Christoph Zwerschke
What answers have you received that have not been satisfactory? I googled a little bit and haven't found many answers at all. Some were in the posting I mentioned: Stuff should go into the standard lib only when it is mature and right enough. However, we are already at Python 2.4 and there is

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Christoph Zwerschke
[EMAIL PROTECTED] schrieb: By ordered dict, one usually wants order that is arbitary which cannot be derived from the content, say insertion order(most ordered dict I saw use this order). I am writing a web applications(simple forms) which has a number of fields. Each field naturally has a

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Ben Finney
[restored my attribution line so we know who said what] Christoph Zwerschke [EMAIL PROTECTED] wrote: Ben Finney wrote: In what cases do you find yourself needing a dict that preserves its key order? Can you present a use case that would be improved by an ordered dict? There are too many

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Fredrik Lundh
Christoph Zwerschke wrote: The example above is a bit misleading, because using 'a', 'b' as keys can give the impression that you just have to sort() the keys to have what you want. So let's make it more realistic: d = { 'pid': ('Employee ID', 'int'), 'name': ('Employee name',

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: but you can easily generate an index when you need it: index = dict(d) name, type = index[pid] print name the index should take less than a microsecond to create, and since it points to the members of the original dict, it doesn't use much memory

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Christoph Zwerschke
Fredrik Lundh wrote: if you restructure the list somewhat d = ( ('pid', ('Employee ID', 'int')), ('name', ('Employee name', 'varchar')), ('sal', ('Salary', 'float')) ) you can still loop over the list ... but you can easily generate an index when you

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Ben Finney wrote: Another possibility: ordered dictionaries are not needed when Python 2.4 has the 'sorted' builtin. What does sorted() have anythng to do with orders like insertion order, or some arbitary order that instead of a,b,c,d,e, I want it as e, c, b, d, a ? Personally, I have needs

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Christoph Zwerschke
Ben Finney wrote: Without an example, it's hard to know what you want to do and whether an ordered dictionary is the best way to do it. I have indicated an example, discussed in more detail in another subthread. There are already enough competing implementations. Have they been sufficiently

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Christoph Zwerschke wrote: [EMAIL PROTECTED] wrote: Personally, I have needs for ordered dict but I don't think it should be in standard library though, as different situation called for different behaviour for ordered and skewing my code to a standard lib way is no good. I have

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Christoph Zwerschke
[EMAIL PROTECTED] wrote: Personally, I have needs for ordered dict but I don't think it should be in standard library though, as different situation called for different behaviour for ordered and skewing my code to a standard lib way is no good. I have started the thread in the first place

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... there are at least two behaviour. What I need is a preferred order. Say if I have designed a web form(correspond to a database table), I just want say 3 fields that goes before anything else in the presentation. The rest I don't care as the DBA

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Alex Martelli
Christoph Zwerschke [EMAIL PROTECTED] wrote: ... I have started the thread in the first place because I believed it is pretty unabmiguous what an ordered dictionary is and how it should I think you're wrong here. People in the past who have requested or implemented stuff they called

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Alex Martelli
Christoph Zwerschke [EMAIL PROTECTED] wrote: ... The 'sorted' function does not help in the case I have indicated, where I do not want the keys to be sorted alphabetically, but according to some criteria which cannot be derived from the keys themselves. Ah, but WHAT 'some criteria'?

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Mike Meyer
Christoph Zwerschke [EMAIL PROTECTED] writes: Ben Finney wrote: Another possibility: ordered dictionaries are not needed when Python 2.4 has the 'sorted' builtin. The 'sorted' function does not help in the case I have indicated, where I do not want the keys to be sorted alphabetically, but

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Alex Martelli wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... there are at least two behaviour. What I need is a preferred order. Say if I have designed a web form(correspond to a database table), I just want say 3 fields that goes before anything else in the presentation. The

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Peter Hansen
[EMAIL PROTECTED] wrote: Using the same logic, we don't need types other than string in a DBMS as we can always convert a string field into some other types when it is needed. You mean, like SQLite does? (http://www.sqlite.org/datatypes.html) -Peter --

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Peter Hansen wrote: [EMAIL PROTECTED] wrote: Using the same logic, we don't need types other than string in a DBMS as we can always convert a string field into some other types when it is needed. You mean, like SQLite does? (http://www.sqlite.org/datatypes.html) Yup, they are using

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Bengt Richter
On Sun, 20 Nov 2005 22:03:34 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Ordering the keys isn't the normal case, and can be done easily when needed. That depends. Maybe I do not want the keys to be sorted alphabetically, but according to some criteria which cannot be derived from the

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Bengt Richter wrote: On Sun, 20 Nov 2005 22:03:34 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Ordering the keys isn't the normal case, and can be done easily when needed. That depends. Maybe I do not want the keys to be sorted alphabetically, but according to some criteria

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Ben Finney
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: [sort by] some other metadata that is not present in the data. [...] Of course, you may say, just put another column that represent this(some reporting programs I have seen do it this way) and that is an option but not the only option. It's a pretty

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Ben Finney wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: [sort by] some other metadata that is not present in the data. [...] Of course, you may say, just put another column that represent this(some reporting programs I have seen do it this way) and that is an option but not the

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: Fredrik Lundh wrote: but you can easily generate an index when you need it: index = dict(d) name, type = index[pid] print name the index should take less than a microsecond to create, and since it points to the members of the original dict,

<    1   2