如何检查字典的所有值是否均为0 [英] How to check if all values of a dictionary are 0
本文介绍了如何检查字典的所有值是否均为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查所有值,即对应于字典中所有键的值是否为0.是否有没有循环的方法?如果可以,怎么办?
I want to check if all the values, i.e values corresponding to all keys in a dictionary are 0. Is there any way to do it without loops? If so how?
推荐答案
使用all()
:
all(value == 0 for value in your_dict.values())
如果给定的iterable的所有元素都为true,则
all
返回True
.
all
returns True
if all elements of the given iterable are true.
这篇关于如何检查字典的所有值是否均为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文