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
1349
+
### > Modifying a dictionary while iterating over it/迭代字典时的修改
1350
1350
1351
1351
```py
1352
1352
x = {0: None}
@@ -1370,14 +1370,14 @@ for i in x:
1370
1370
7
1371
1371
```
1372
1372
1373
-
Yes, it runs for exactly **eight** times and stops.
1373
+
是的, 它运行了**八次**然后才停下来.
1374
1374
1375
-
#### 💡 Explanation:
1375
+
#### 💡 说明:
1376
1376
1377
-
* Iteration over a dictionary that you edit at the same time is not supported.
1378
-
* 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.
1379
-
* How deleted keys are handled and when the resize occurs might be different for different Python implementations.
1380
-
* 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