在迭代它时从Python中删除字典中的项是否合法?
例如:
for k, v in mydict.iteritems(): if k == val: del mydict[k]
我们的想法是从字典中删除不符合某个条件的元素,而不是创建一个新字典,该字典是被迭代的字典的子集.
这是一个好的解决方案吗?有更优雅/有效的方式吗?
python scripting dictionary
dictionary ×1
python ×1
scripting ×1