-3

I have a list of dicts e.g. [{'X':0,'Y':0},{'X':1,'Y':2}] and I want to check to see if every X and Y value is equal to 0. I have tried some methods such as the all() function and the .values() function but I have been unsuccessful but maybe I have been using them wrong.

I tried all(value=={'X':0,'Y':0} for value in mydict) but to no success. Does anyone have any suggestions?

Jack Timber
  • 45
  • 1
  • 1
  • 5

1 Answers1

0

I think what is missing is the .values() operator?

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.')
Shawn Ramirez
  • 796
  • 1
  • 5
  • 10