Re: Dictionary order?

2022-08-01 Thread Weatherby,Gerard
I don’t see what is surprising. The interface for a dictionary never specified the ordering of the keys, so I would not be surprised to see it vary based on release, platform, values of keys inserted, number of items in the dictionary, etc. — Gerard Weatherby | Application Architect NMRbox

Re: Dictionary order?

2022-08-01 Thread Dan Stromberg
On Mon, Aug 1, 2022 at 4:42 PM Dan Stromberg wrote: > > > Yes, but I'm pretty sure that's been true for a LONG time. The hashes >> > for small integers have been themselves for as long as I can remember. >> > But the behaviour of the dictionary, when fed such keys, is what's >> > changed. >> >> I

Re: Dictionary order?

2022-08-01 Thread Dan Stromberg
On Mon, Aug 1, 2022 at 3:25 PM <2qdxy4rzwzuui...@potatochowder.com> wrote: > On 2022-08-02 at 07:50:52 +1000, > Chris Angelico wrote: > > > On Tue, 2 Aug 2022 at 07:48, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > > > > > On 2022-08-01 at 13:41:11 -0700, > > > Dan Stromberg wrote: > > > > > >

Re: Dictionary order?

2022-08-01 Thread 2QdxY4RzWzUUiLuE
On 2022-08-02 at 07:50:52 +1000, Chris Angelico wrote: > On Tue, 2 Aug 2022 at 07:48, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > > > On 2022-08-01 at 13:41:11 -0700, > > Dan Stromberg wrote: > > > > > keys = [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7, 12, 11] > > > > > > dict_ = {} > > > for key i

Re: Dictionary order?

2022-08-01 Thread Chris Angelico
On Tue, 2 Aug 2022 at 07:48, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2022-08-01 at 13:41:11 -0700, > Dan Stromberg wrote: > > > keys = [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7, 12, 11] > > > > dict_ = {} > > for key in keys: > > dict_[key] = 1 > > $ python > Python 3.10.5 (main, Jun 6 2

Re: Dictionary order?

2022-08-01 Thread 2QdxY4RzWzUUiLuE
On 2022-08-01 at 13:41:11 -0700, Dan Stromberg wrote: > keys = [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7, 12, 11] > > dict_ = {} > for key in keys: > dict_[key] = 1 $ python Python 3.10.5 (main, Jun 6 2022, 18:49:26) [GCC 12.1.0] on linux Type "help", "copyright", "credits" or "license" for more

Re: Dictionary order?

2022-08-01 Thread Dan Stromberg
On Mon, Aug 1, 2022 at 1:41 PM Dan Stromberg wrote: > On 1.4 through 2.1 I got descending key order. I expected the keys to be > scattered, but they weren't. > I just noticed that 1.4 was ascending order too - so it was closer to 2.2 than 1.5. I guess that's kind of beside the point though - it

Re: Dictionary order?

2022-08-01 Thread Chris Angelico
On Tue, 2 Aug 2022 at 06:50, Skip Montanaro wrote: > > > > > So I decided to write a little test program to run on a variety of > > CPythons, to confirm what I was thinking. > > > > And instead I got a surprise. > > > > On 1.4 through 2.1 I got descending key order. I expected the keys to be > >

Re: Dictionary order?

2022-08-01 Thread Skip Montanaro
> > So I decided to write a little test program to run on a variety of > CPythons, to confirm what I was thinking. > > And instead I got a surprise. > > On 1.4 through 2.1 I got descending key order. I expected the keys to be > scattered, but they weren't. > > On 2.2 through 3.5 I got ascending ke

Dictionary order?

2022-08-01 Thread Dan Stromberg
Hi folks. I'm still porting some code from Python 2.7 to 3.10. As part of that, I saw a list being extended with a dict.values(), and thought perhaps it wasn't ordered as intended on Python 2.7, even though the problem would conceivably just disappear on 3.10. So I decided to write a little test

Re: Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-28 Thread Steve D'Aprano
On Mon, 29 May 2017 12:15 am, Jon Ribbens wrote: > On 2017-05-28, Steve D'Aprano wrote: >> What exactly did you think I got wrong? > > 3.6 does preserve the dict order. It isn't a guarantee so may change > in future versions, but it is what 3.6 actually does. Did I say it didn't? I said you ca

Re: Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-28 Thread Ian Kelly
On May 28, 2017 8:23 AM, "Jon Ribbens" wrote: > On 2017-05-28, Steve D'Aprano wrote: >> What exactly did you think I got wrong? > > 3.6 does preserve the dict order. It isn't a guarantee so may change > in future versions, but it is what 3.6 actually does. No, it's what CPython 3.6 actually does

Re: Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-28 Thread Jon Ribbens
On 2017-05-28, Steve D'Aprano wrote: > What exactly did you think I got wrong? 3.6 does preserve the dict order. It isn't a guarantee so may change in future versions, but it is what 3.6 actually does. >> If you're asking "given a fixed Python version, and where appropriate >> PYTHONHASHSEED=0,

Re: Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-28 Thread Steve D'Aprano
On Sun, 28 May 2017 11:12 pm, Jon Ribbens wrote: > On 2017-05-28, Bill Deegan wrote: >> As a follow up to a discussion on IRC #python channel today. >> >> Assuming the same order of insertions of the same items to a dictionary >> would the iteration of a dictionary be the same (not as the order o

Re: Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-28 Thread Jon Ribbens
On 2017-05-28, Bill Deegan wrote: > As a follow up to a discussion on IRC #python channel today. > > Assuming the same order of insertions of the same items to a dictionary > would the iteration of a dictionary be the same (not as the order of > insertion, just from run to run) for Python 2.7 up t

Re: Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-27 Thread Steve D'Aprano
> insertion, just from run to run) for Python 2.7 up to python 3.3? That's not a language promise. The dictionary order is explicitly an implementation detail. It might happen to be true by *accident* that different versions of Python give the same order, but that's not guaran

Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-27 Thread Bill Deegan
Greetings, As a follow up to a discussion on IRC #python channel today. Assuming the same order of insertions of the same items to a dictionary would the iteration of a dictionary be the same (not as the order of insertion, just from run to run) for Python 2.7 up to python 3.3? And again at Pytho