You can chain elements into one tuple:
from itertools import chain,combinations
list_with_tuples=[(1,), (2,), (3,)]
di = {tuple(chain.from_iterable(comb)):"value" for comb in combinations(list_with_tuples, 2)}
print(di)
{(1, 2): 'value', (1, 3): 'value', (2, 3): 'value'}
It will work for any length combinations.
If you have another container that matters, you can pin:
from itertools import chain,combinations
list_with_tuples=[(1,), (2,), (3,)]
values = [1,2,3]
di = {tuple(chain.from_iterable(comb)): val for comb,val in zip(combinations(list_with_tuples, 2),values)}
print(di)
{(1, 2): 1, (1, 3): 2, (2, 3): 3}
source
share