I prefer @JollyJumper's solution for readability, although this is faster
>>> from itertools import combinations >>> d = {"one": [1, 2, 3], "two": [2, 3, 4], "three": [3, 4, 5]} >>> [{j: d[j] for j in i} for i in combinations(d, 2)] [{'three': [3, 4, 5], 'two': [2, 3, 4]}, {'three': [3, 4, 5], 'one': [1, 2, 3]}, {'two': [2, 3, 4], 'one': [1, 2, 3]}]
Timings:
>python -m timeit -s "d = {'three': [3, 4, 5], 'two': [2, 3, 4], 'one': [1, 2, 3]}; from itertools import combinations" "map(dict, combinations(d.iteritems(), 2))" 100000 loops, best of 3: 3.27 usec per loop >python -m timeit -s "d = {'three': [3, 4, 5], 'two': [2, 3, 4], 'one': [1, 2, 3]}; from itertools import combinations" "[{j: d[j] for j in i} for i in combinations(d, 2)]" 1000000 loops, best of 3: 1.92 usec per loop