繁体   English   中英

检查 python 中对象字典的值

[英]Checking values for a dict of objects in python

我有一个字典列表,例如[{'X':0,'Y':0},{'X':1,'Y':2}]我想检查是否每个 X 和 Y 值都是等于 0。我尝试了一些方法,例如 all() function 和 the.values() function,但我一直没有成功,但也许我一直在错误地使用它们。

我尝试all(value=={'X':0,'Y':0} for value in mydict)但没有成功。 有没有人有什么建议?

我认为缺少的是 the.values() 运算符?

ListOfDicts= [{'X':0,'Y':0},{'X':1,'Y':2}] 


for  dictionaryIndex in range(len(ListOfDicts)):
    result = all(value==0 for value in ListOfDicts[dictionaryIndex].values())

    if result == True:
        print ('The values in the dictionary at index : ' + str(dictionaryIndex) + ' ARE equal to zero.')
    else :
        print ('The values in the dictionary at index : ' + str(dictionaryIndex) + ' are NOT equal to zero.')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM