Maybe something like
>>> import itertools >>> >>> d = {1:2, 2:3, 3:4} >>> >>> for k0, k1 in itertools.combinations(d,2): ... print 'compare', k0, k1 ... compare 1 2 compare 1 3 compare 2 3
if it doesn't matter to you whether you get (1,2) or (2,1). [Of course, you could sorted(d) over sorted(d) or some option if you would like to get a certain order, or compare both (k0, k1) and (k1, k0) if that matters.]
[BTW: do not name your list of lists or your dicts dict - which captures the built-in functions, and they are convenient to use.]
source share