Not to be confused with this question in Stackoverflow.
I have a list called a = [2, 3, 4, 1]
I have some function say func(), which is as follows:
def func(a):
o = []
n = len(a)
for i in range(n):
x=a[:]
x[i],x[(i+1)%n] = x[(i+1)%n],x[i]
o.append(x)
return o
and func(a) produces another list as follows:
[[3, 2, 4, 1], [2, 4, 3, 1], [2, 3, 1, 4], [1, 3, 4, 2]]
Now I want to map the output list to the list from which it is generated. So, how to generate a dictionary in the following format:
a : o
key : value1, value2........last value
[2, 3, 4, 1] : [3, 2, 4, 1], [2, 4, 3, 1], [2, 3, 1, 4], [1, 3, 4, 2]
{tuple(a): func(a)}? (Minor detail: you can't have alistas a key so I converted it into atupleinstead.) The real question is why you want this, since all you have is a dictionary with one element – do you have multiple values ofa?