You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### > Modifying a dictionary while iterating over it
1344
+
### > Modifying a dictionary while iterating over it/迭代字典时的修改
1345
1345
1346
1346
```py
1347
1347
x = {0: None}
@@ -1365,14 +1365,14 @@ for i in x:
1365
1365
7
1366
1366
```
1367
1367
1368
-
Yes, it runs for exactly **eight** times and stops.
1368
+
是的, 它运行了**八次**然后才停下来.
1369
1369
1370
-
#### 💡 Explanation:
1370
+
#### 💡 说明:
1371
1371
1372
-
* Iteration over a dictionary that you edit at the same time is not supported.
1373
-
* It runs eight times because that's the point at which the dictionary resizes to hold more keys (we have eight deletion entries, so a resize is needed). This is actually an implementation detail.
1374
-
* How deleted keys are handled and when the resize occurs might be different for different Python implementations.
1375
-
* For more information, you may refer to this StackOverflow [thread](https://stackoverflow.com/questions/44763802/bug-in-python-dict) explaining a similar example in detail.
0 commit comments