I needed to test if the values of all entries in a dictionary were equal
but since the values themselves were dictionaries I couldn't simply take a
set of the values and test if this equated to one. So I ended up taking all
combination of the keys and testing pairs of sub dictionaries. I just want
to check that there isn't a more direct way of doing this that testing all
combinations?


import itertools

dictmain={"K1": {1:"SD_V1",2:"SD_V2"},
          "K2": {1:"SD_V1",2:"SD_V2"},
          "K3": {1:"SD_V1",2:"SD_V2"}}

for compare in list(itertools.combinations(dictmain,2)):
    print "Comparing dictionaries:", compare

    if dictmain[compare[0]]==dictmain[compare[1]]:
        print "comb dict are equal"
    else:
        print "comb dict are NOT equal"
        break


Many thanks in advance,
Jignesh
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to