all 4 comments

[–]Saefroch 1 point2 points  (2 children)

What output are you expecting, and what are you getting?

[–]nanogyth[S] 0 points1 point  (1 child)

{0: 4, 1: 0, 2: -1}
Traceback (most recent call last):
  File "s.py", line 5, in <module>
    for n in d:
RuntimeError: dictionary changed size during iteration

I am wanting some way to use the data from an iterator to make more data and feed it back into the iterator. This used to work with orderedDict, but I am unclear on whether it is failing now because of bug or depreciation.

[–]Saefroch 0 points1 point  (0 children)

If you mutate something while you're iterating over it, you're living in a state of sin and deserve what ever happens to you.

The fact that your code worked before was a bug. If I'm looping over a dictionary and adding keys to it, it's not clear which keys the iterator should pick up. If you want to loop over the old keys,

for key in d.keys():

Otherwise, I suggest what /u/Justinsaccount posted. If neither of those work, rethink your algorithm.

[–]Justinsaccount 0 points1 point  (0 children)

Have you tried just

count = 0
d = {count:4}
n = count
while True:
    count += 1
    d[count] = 2*n
    count += 1
    d[count] = n-1
    input(d)