python - check if any value of dict is not None (without iterators)

后端 未结 2 1157
离开以前
离开以前 2021-02-05 06:39

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         


        
2条回答
  •  借酒劲吻你
    2021-02-05 07:20

    You can use

    nones = not all(d.values())
    

    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.

提交回复
热议问题