python 字典元素删除

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wshzd/article/details/78250339

for k,v in list(word_freq.items()):
    if v<4:
        del word_freq[k]
注意:首先需要把字典的item转化成list才可以,否则会报错:RuntimeError: dictionary changed size during iteration




猜你喜欢

转载自blog.csdn.net/wshzd/article/details/78250339