标签:删除 iter lis during 列表 change nbsp error erro
1 a = {‘1‘:11, ‘2‘:0, ‘3‘:0} 2 for b in list(a.keys()): 3 if a[b] == 0: 4 del a[b] 5 6 print(a)
报错是因为在字典迭代期间改变字典大小
我们可以通过取出字典的键值,在转化为列表,这样在for循环期间就可以删除了
python 报错RuntimeError: dictionary changed size during iteration
标签:删除 iter lis during 列表 change nbsp error erro
原文地址:https://www.cnblogs.com/lonelyshy/p/9775717.html