[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Tim Peters
Tim Peters added the comment: Not without more expense. Which is why it hasn't been done. But this is a wrong place to talk about it. If you want Python to change, go to the python-ideas mailing list? https://mail.python.org/mailman/listinfo/python-ideas -- _

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Sapan
Sapan added the comment: Aha I did have that in mind while writing the code. I guess a warning could have helped. Can that be introduced ? -- ___ Python tracker ___ _

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Tim Peters
Tim Peters added the comment: Questions about Python should be asked, e.g., on the Python mailing list. The short course is that it's desired that iterating over dicts be as fast as possible, and nobody knows a way to make iteration robust in the face of mutations that wouldn't be significan

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Ammar Askar
Ammar Askar added the comment: Think about what it means to iterate over a hashmap. Let's say your pop() causes the dictionary to become smaller than the resizing threshold and now the indexes need to be rebuilt, how would this be handled gently by the iterator? This situation is not just so

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Sapan
Sapan added the comment: Thanks for the response btw -- status: pending -> closed ___ Python tracker ___ ___ Python-bugs-list maili

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Sapan
Sapan added the comment: Fair enough. Would like to know the reason though, why is this run time error acceptable ? -- status: closed -> pending ___ Python tracker ___ __

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Tim Peters
Tim Peters added the comment: This won't be changed. The effect on the iteration order of adding and/or removing keys from a dict while iterating over it has never been defined in Python, and never will be. The Python 3 docs for dict views say this clearly: """ Iterating views while adding

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Sapan
Sapan added the comment: As for creating a new list all together will require quite a lot of work as this particular json is huge and many keys contain periods. Plus there are multiple jsons. I still believe there should be a better way to handle this. -- status: closed -> pending _

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Sapan
Sapan added the comment: It makes sense that the it wont re-iterate, but this scenario is totally legit and should be handled in a better way. Iterating through items does not really help here because that will give me a tuple and they are immutable. -- _

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Ammar Askar
Ammar Askar added the comment: Modifying containers while iterating over them is generally not safe. In this case the iterator at the point you start the loop will contain all the items to iterate over, adding them mid-loop will not cause them to be iterated over. Take a look at the last sec

[issue35023] Missed a key when iterating over dictionary

2018-10-18 Thread Sapan
New submission from Sapan : The issue occurs in the second level of nested dictionary.Iterating over nested dictionary and editing the key by popping the old key and entering the new key. The next iteration, at the second level of nested dictionary, then skips the second key in dictionary and