Dictionary order?

Chris Angelico rosuav at gmail.com
Mon Aug 1 17:50:52 EDT 2022


On Tue, 2 Aug 2022 at 07:48, <2QdxY4RzWzUUiLuE at potatochowder.com> wrote:
>
> On 2022-08-01 at 13:41:11 -0700,
> Dan Stromberg <drsalists at gmail.com> 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 information.
> >>> [hash(x) for x in range(20)]
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>
> Just sayin'.  :-)

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.

ChrisA


More information about the Python-list mailing list