RE: Ordered dict by default

2009-02-08 Thread Delaney, Timothy (Tim)
bearophileh...@lycos.com wrote: > I have missed another example: It may be possible to create a sorting > routine that's not stable but is faster than the current stable > timsort (for example in C++ STL you have both sorting routines, and > the unstable one is a variant of introsort that is faste

Re: Ordered dict by default

2009-02-06 Thread MRAB
bearophileh...@lycos.com wrote: Cameron Simpson: increases the unrealised assumptions about mappings in general which a newbie may acquire, causing them pain/complaint later with other mappings< This is wrong in several different ways. I would much rather keep dictionaries as performant as

Re: Ordered dict by default

2009-02-06 Thread bearophileHUGS
bearophile: > In Python 3 strings are all unicode, integral numbers are all > multiprecision, chars in Python 2.x+ are strings, lists are arrays > that can grow dynamically, and so on because the Purpose of Python > isn't to be as fast as possible, but to be first of all flexible, > safe, easy, not

Re: Ordered dict by default

2009-02-06 Thread bearophileHUGS
Cameron Simpson: >increases the unrealised assumptions about mappings in general which a newbie >may acquire, causing them pain/complaint later with other mappings< This is wrong in several different ways. > I would much rather keep dictionaries as performant as possible, as a > bare mapping,

Re: Ordered dict by default

2009-02-06 Thread MRAB
Cameron Simpson wrote: On 05Feb2009 01:47, bearophileh...@lycos.com wrote: | [...] But even if the average performance becomes a | little worse I think making the default Python dict as ordered is a | positive change for Python too, because built-ins are meant to be as | flexible as possible, ev

Re: Ordered dict by default

2009-02-06 Thread Cameron Simpson
On 05Feb2009 01:47, bearophileh...@lycos.com wrote: | [...] But even if the average performance becomes a | little worse I think making the default Python dict as ordered is a | positive change for Python too, because built-ins are meant to be as | flexible as possible, even if they aren't the fas

Re: Ordered dict by default

2009-02-05 Thread Terry Reedy
andrew cooke wrote: so what is happening with pep 372? http://www.python.org/dev/peps/pep-0372/ There seems to be a number of unanswered questions as to the exact behavior (see Q and A section). The author needs to promote more discussion by those interested, including here, and make a deci

Re: Ordered dict by default

2009-02-05 Thread Terry Reedy
Paul Rubin wrote: bearophileh...@lycos.com writes: Now Ruby dicts are ordered by default: http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Maybe I didn't read that carefully enough, but it looks like "ordered" means the dict records come out in the same order you inserted them

Re: Ordered dict by default

2009-02-05 Thread Steve Holden
bearophileh...@lycos.com wrote: > Bryan Olson: >> A few bits fuzzy. Is the following True or False if dict is insert-ordered? >> dict(a=6, b=7) == dict(b=7, a=6) > > In my odict implementation I have disallowed that syntax because if > you want to define a mydict(**kwds) function that allows a

Re: Ordered dict by default

2009-02-05 Thread bearophileHUGS
Bryan Olson: > A few bits fuzzy. Is the following True or False if dict is insert-ordered? >     dict(a=6, b=7) == dict(b=7, a=6) In my odict implementation I have disallowed that syntax because if you want to define a mydict(**kwds) function that allows a syntax like: mydict(a=6, b=7) it takes

Re: Ordered dict by default

2009-02-05 Thread Bryan Olson
Stephen Hansen wrote: Ooh, as an addendum... I found one case where I want insertion-and-update order: meaning that its an ordered dictionary that maintains insertion order, but an update to a particular item moves that item to the back so an update behaves like del d[key]; d[key] = value in term

Re: Ordered dict by default

2009-02-05 Thread Bryan Olson
MRAB wrote: Paul Rubin wrote: bearophileh...@lycos.com writes: Now Ruby dicts are ordered by default: http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Maybe I didn't read that carefully enough, but it looks like "ordered" means the dict records come out in the same order you i

Re: Ordered dict by default

2009-02-05 Thread MRAB
Paul Rubin wrote: bearophileh...@lycos.com writes: Now Ruby dicts are ordered by default: http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Maybe I didn't read that carefully enough, but it looks like "ordered" means the dict records come out in the same order you inserted them

Re: Ordered dict by default

2009-02-05 Thread Stephen Hansen
> Now, I also do recognize the utility of ordered dictionaries in some cases, > but > exactly what you mean by ordered varies. I have two cases where "ordered" > has the keys are in a specific custom order. I have four cases where "ordered" > means maintaining insertion order. For the former I do

Re: Ordered dict by default

2009-02-05 Thread Stephen Hansen
> That page about Ruby dicts show a higher traversal speed (probably > just because the CPU has to scan less memory, but I am not sure, > because mordern CPUs are very complex) but lower insertion speed (I > think mostly not because the added management of two pointers, but > because the memory use

Re: Ordered dict by default

2009-02-05 Thread Christian Heimes
andrew cooke schrieb: > so what is happening with pep 372? > > http://www.python.org/dev/peps/pep-0372/ It's still a draft and hasn't been implemented yet. Now is the time to get it ready for Python 3.1 and 2.7. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: Ordered dict by default

2009-02-05 Thread andrew cooke
so what is happening with pep 372? http://www.python.org/dev/peps/pep-0372/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Ordered dict by default

2009-02-05 Thread Duncan Booth
Paul Rubin wrote: > Duncan Booth writes: >> If you want to write doctests then any stable order in the default >> dict type would be helpful no matter whether it means that keys are >> in original insertion or latest insertion order or sorted. > > Just use "sorted"

Re: Ordered dict by default

2009-02-05 Thread Paul Rubin
Duncan Booth writes: > If you want to write doctests then any stable order in the default dict > type would be helpful no matter whether it means that keys are in original > insertion or latest insertion order or sorted. Just use "sorted" in the test code: >>> print sorted(dict((a**2,a) for a

Re: Ordered dict by default

2009-02-05 Thread Duncan Booth
Paul Rubin wrote: > bearophileh...@lycos.com writes: >> Now Ruby dicts are ordered by default: >> http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ > > Maybe I didn't read that carefully enough, but it looks like "ordered" > means the dict records com

Re: Ordered dict by default

2009-02-05 Thread Paul Rubin
Steve Holden writes: > In mathematics mappings aren't ordered either, and a pure dict is pretty > much a mapping. So leave them alone, they are fine as they are! Ehhh, an ordered dict has to support a comparison operation on the keys, while a Python dict has to support a hashing operation on them

Re: Ordered dict by default

2009-02-05 Thread Paul Rubin
bearophileh...@lycos.com writes: > Now Ruby dicts are ordered by default: > http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Maybe I didn't read that carefully enough, but it looks like "ordered" means the dict records come out in the same order you inserted them in. That is if yo

Re: Ordered dict by default

2009-02-05 Thread Steve Holden
bearophileh...@lycos.com wrote: [a somewhat feeble case for ordered dicts] > Once the default dicts are ordered, it can be possible to add an > unordereddict to the collections module to be used by programmers when > max performance or low memory usage is very important :-) > I have no real idea w