Alternative solutions
If you are looking for the smallest value in a dictionary, you can do this:
min(dictionary.values())
If you cannot use min, you can use sorted:
sorted(dictionary.values())[0]
Why am I getting this error?
On the other hand, the reason you are experiencing a Runtime Error is because in the inner loop you are modifying the iterator that your outer loop is based on. When you pop record that has not yet been reached by the external loop, and the external iterator reaches it, it tries to access the remote element, thereby causing an error.
If you try to execute your Python 2.7 code (instead of 3.x), you will get, in essence, Key Error .
What can I do to avoid a mistake?
If you want to change the iterability within the loop based on your iterator, you should use a deep copy .
Nadir sampaoli
source share