Re: Problem with OrderedDict - progress report

2018-06-01 Thread Chris Angelico
On Sat, Jun 2, 2018 at 9:10 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> if you 'break' immediately after a mutation, that isn't >> continuing to iterate. Even though you're inside the loop, there's no >> further action taken to process the loop, and no problem. > > > Yes, but you're als

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Gregory Ewing
Chris Angelico wrote: if you 'break' immediately after a mutation, that isn't continuing to iterate. Even though you're inside the loop, there's no further action taken to process the loop, and no problem. Yes, but you're also not calling next() again, so no exception would be triggered. My po

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Steven D'Aprano
On Thu, 31 May 2018 16:37:39 +0200, Frank Millman wrote: [...] > Agreed, but my gut feel, and the following example, suggest that when > processing the last key in a dictionary while iterating over it, you > have not yet stopped iterating. > d = {} d[1] = 'one' d[2] = 'two' Before

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Frank Millman
"Gregory Ewing" wrote in message news:fnccd8ff3s...@mid.individual.net... Chris Angelico wrote: > It is an error to mutate the dictionary *and then continue to iterate > over it*. But if you're processing the last key, and you add one so that it's no longer the last key, what should happen?

Re: Problem with OrderedDict - progress report

2018-06-01 Thread INADA Naoki
On Fri, Jun 1, 2018 at 4:56 PM Gregory Ewing wrote: > Chris Angelico wrote: > > It is an error to mutate the dictionary *and then continue to iterate > over it*. > > But if you're processing the last key, and you add one so > that it's no longer the last key, what should happen? > > My feeling is

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Chris Angelico
On Fri, Jun 1, 2018 at 5:54 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> It is an error to mutate the dictionary *and then continue to iterate over >> it*. > > > But if you're processing the last key, and you add one so > that it's no longer the last key, what should happen? > > My feeli

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Gregory Ewing
Chris Angelico wrote: It is an error to mutate the dictionary *and then continue to iterate over it*. But if you're processing the last key, and you add one so that it's no longer the last key, what should happen? My feeling is that this should be an error, because it's not clear whether itera

Re: Problem with OrderedDict - progress report

2018-05-31 Thread Chris Angelico
On Fri, Jun 1, 2018 at 12:37 AM, Frank Millman wrote: > "Steven D'Aprano" wrote in message news:peorib$1f4$2...@blaine.gmane.org... >> >> >> On Thu, 31 May 2018 10:05:43 +0200, Frank Millman wrote: >> >> > From the interpreter session below, you will see that adding a key while >> > processing th

Re: Problem with OrderedDict - progress report

2018-05-31 Thread Frank Millman
"Steven D'Aprano" wrote in message news:peorib$1f4$2...@blaine.gmane.org... On Thu, 31 May 2018 10:05:43 +0200, Frank Millman wrote: > From the interpreter session below, you will see that adding a key while > processing the *last* key in an OrderedDict does not give rise to an > exception. I

Re: Problem with OrderedDict - progress report

2018-05-31 Thread Steven D'Aprano
On Thu, 31 May 2018 10:05:43 +0200, Frank Millman wrote: > "Frank Millman" wrote in message news:pemchs$r12$1...@blaine.gmane.org... >> >> So working backwards, I have solved the first problem. I am no nearer >> to > figuring out why it fails intermittently in my live program. The message > from

Re: Problem with OrderedDict - progress report

2018-05-31 Thread Frank Millman
"Frank Millman" wrote in message news:pemchs$r12$1...@blaine.gmane.org... So working backwards, I have solved the first problem. I am no nearer to figuring out why it fails intermittently in my live program. The message from INADA Naoki suggests that it could be inherent in CPython, but I am n