I have a list: v = [1,2,2,3]. I would like to use this list as a key. I can do it “manually”:
x = {}
x[1,2,2,3] = 7
But
x[v] = 7
does not work. What is the easiest way to do what I need to do?
ADDED
I imagine the solution as something like that:
x[open(v)] = 7
The problem is that keys must be immutable, which lists are not. Tuples, however, are.
Simply convert
vto a tuple:To elaborate, the above is the same as writing
and the latter is a syntactic variation of