I’d like to compare a Python dictionary with itself. For example:
for key1 in d:
for key2 in d:
if key1 == key2:
continue
compare(d[key1],d[key2])
The above would work except I’m comparing key1 with key 2 and then later the reverse (key2 with key1). The range of the second for-loop should really start after key1 to avoid repeated comparisons. How can that be done?
I think that
itertools.combinationswould be helpful hereso, for your case, you’d want:
Here’s a silly example where I construct a list of pairs of people with brown eyes (or hair I suppose …):