I'm attempting to sort two values drawn from the indices of a list so that the key in a dictionary is alway some pair of values (x,y) such that x < y.
Given, for example:
a = [['0', '1', '.5'], ['3', '1', '.7'], ['18','16','.4']]
I would like d[(16, 18)] = .4, with all numbers in the key turned into integers in order from smallest to largest, and the value as a float.
Here's what I've tried:
a = [['0', '1', '.5'], ['3', '1', '.7'], ['18','16','.4']]
d = {}
for i in a:
b = sorted([int(i[0]), int(i[1])])
d[*b] = float(i[2])
I read about unpacking a list here and thought I'd give it a go, but I'm getting a SyntaxEror on the asterisk. Help?