python-检查dict的任何值是否不为None(无迭代器) [英] python - check if any value of dict is not None (without iterators)
本文介绍了python-检查dict的任何值是否不为None(无迭代器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有可能获得与此代码相同的输出:
I wonder if it is possible to gain the same output as from this code:
d = {'a':None,'b':'12345','c':None}
nones=False
for k,v in d.items():
if d[k] is None:
nones=True
或
any([v==None for v in d.values()])
但没有for循环迭代器或生成器?
but without a for loop iterator, or generator?
推荐答案
您可以使用
nones = not all(d.values())
如果所有值都不为None,则nones将设置为False,否则设置为True.不过,这只是一个抽象,它必须在内部遍历值列表.
If all values are not None, nones would be set to False, else True. It is just an abstraction though, internally it must iterate over values list.
这篇关于python-检查dict的任何值是否不为None(无迭代器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文