Note: I am assuming that the values in the list are unique and you have flexibility to use indexes of actual values (or you are ready to sacrifice time)
If you really want to save space , i would suggest you to use list of lists to store values for each combination. You do not actually need to store mapping (a,b) -> x.
For example, consider the list:
a = [1,2,3,4]
Suppose Combinations/value pairs are:
(1,2) -> 2, (1,3) -> 3, (1,4) -> 4, (2,3) -> 5, (2,4) -> 6, (3,4) -> 7
The storage for combination/value pair will look like:
comb_value = [[2,3,4],[5,6],[7]]
Retrieval:
Assuming that list a and comb_value are global. (We will dry run the code simultaneously.)
# Consider that x=2 and y=4.
def comb(x,y):
# if you can use index directly, next 2 lines should be skipped.
x= find_index(x) # Returns 1.
y= find_index(y) # Returns 3.
if x < y :
return _comb(x,y) # calling _comb(1,3)
return _comb(y,x)
# x= 1 and y =3
def _comb(x,y):
return comb_value[x][y-x-1] # returns comb_value[1][3-1] i.e. 6.
setoffrozensets?set(frozenset([a,b,comb(a,b)]), ...)