I'm trying to create a dictionary containing operands [a, b] as the key, and product (a*b) as the value. For example, it would look something like this.
Key (list): [2, 3]
Val (int): 6
My code grabs the operands (paired) and appends them to a list, which resets for every iteration. Then computes the product and stores that into a variable. Then, at the end of each iteration after forming the operand pairs (a, b) and computing the product (a * b), I try to store that into the dictionary h.
key = [] # Resets for each iteration
key.append(a)
key.append(b)
value = a * b
h[key] = value
When attempting to create a dictionary entry, I get the following error.
TypeError: unhashable type: 'list'
Is there any way to create such a dictionary? If so, how would I do it? Or would a tuple be better suited for this problem?