错误代码①
d = {'a':1, 'b':0, 'c':1, 'd':0}
for key, val in d.items():
del(d[k])
错误代码②
d = {'a':1, 'b':0, 'c':1, 'd':0}
for key, val in d.keys():
del(d[k])
正确代码
d = {'a':1, 'b':0, 'c':1, 'd':0}
keys = list(d.keys())
for key, val in keys:
del(d[k])