在遍历过程中删除 RuntimeError: dictionary changed size during iteration 词典原理

dict  not  ok

 

d = {'a': 34, 'b': 435}
rm_k = []
for k in d.keys():
if k == 'a':
d.pop(k)



list  ok

l = ['wer', 'a', 'ccc']
for i in l:
if i == 'a':
l.remove(i)


posted @ 2024-08-02 16:31  papering  阅读(2)  评论(0编辑  收藏  举报