Re: Order of tuples in dict.items()

2007-10-15 Thread Erik Jones
On Oct 15, 2007, at 6:07 PM, Steven D'Aprano wrote: > On Mon, 15 Oct 2007 14:11:27 -0700, John Machin wrote: > >> On Oct 16, 12:47 am, Erik Jones <[EMAIL PROTECTED]> wrote: >> >>> Not between two consecutive reads, no. However, after any >>> resizing of >>> a dict the result of Python's hash f

Re: Order of tuples in dict.items()

2007-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2007 14:11:27 -0700, John Machin wrote: > On Oct 16, 12:47 am, Erik Jones <[EMAIL PROTECTED]> wrote: > >> Not between two consecutive reads, no. However, after any resizing of >> a dict the result of Python's hash function for any given newly >> inserted key is extremely likely to

Re: Order of tuples in dict.items()

2007-10-15 Thread John Machin
On Oct 16, 12:47 am, Erik Jones <[EMAIL PROTECTED]> wrote: > Not between two consecutive reads, no. However, after any resizing > of a dict the result of Python's hash function for any given newly > inserted key is extremely likely to be different than it would have > been before the resizing, i.

Re: Order of tuples in dict.items()

2007-10-15 Thread Erik Jones
On Oct 14, 2007, at 5:27 PM, Steven D'Aprano wrote: > On Sun, 14 Oct 2007 13:26:27 -0700, Erik Max Francis wrote: > >> Will McGugan wrote: >> >>> If I have two dictionaries containing identical values, can I be >>> sure >>> that the items() method will return tuples in the same order? > [...] >>

Re: Order of tuples in dict.items()

2007-10-14 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > I've never seen the point of a sorted dictionary, it's easy to just say: > for key, value in sorted(D.items()) You might want just a subrange of the dictionary (say the 100th through 150th items in sorted order) without having to sort the entire dictio

Re: Order of tuples in dict.items()

2007-10-14 Thread John Machin
On Oct 15, 8:27 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > I've never seen the point of a sorted dictionary, it's easy to just say: > > for key, value in sorted(D.items()) There are several applications that involve finding i such that key[i] <= query < key[i+1] where the

Re: Order of tuples in dict.items()

2007-10-14 Thread Steven D'Aprano
On Sun, 14 Oct 2007 13:26:27 -0700, Erik Max Francis wrote: > Will McGugan wrote: > >> If I have two dictionaries containing identical values, can I be sure >> that the items() method will return tuples in the same order? [...] >> Can I rely on this behavior? > > Probably not. Definitely not. S

Re: Order of tuples in dict.items()

2007-10-14 Thread Erik Max Francis
Will McGugan wrote: > If I have two dictionaries containing identical values, can I be sure > that the items() method will return tuples in the same order? > > I tried an experiment with CPython and it does appear to be the case. > > >>> a=dict(a=1, b=1, c=2) > >>> b=dict(c=2, a=1, b=1) > >>

Re: Order of tuples in dict.items()

2007-10-14 Thread Paul Hankin
On Oct 14, 3:28 pm, Will McGugan <[EMAIL PROTECTED]> wrote: > If I have two dictionaries containing identical values, can I be sure > that the items() method will return tuples in the same order? > ... > Can I rely on this behavior? No. To quote the python documentation: > Keys and values are lis

Order of tuples in dict.items()

2007-10-14 Thread Will McGugan
Hi, If I have two dictionaries containing identical values, can I be sure that the items() method will return tuples in the same order? I tried an experiment with CPython and it does appear to be the case. >>> a=dict(a=1, b=1, c=2) >>> b=dict(c=2, a=1, b=1) >>> a {'a': 1, 'c': 2, 'b': 1} >>