You are viewing a single comment's thread. Return to all comments →
My solution
def permutationEquation(p): return [p.index(p.index(x) + 1) + 1 for x in sorted(p)]
I am just learning Python, so the syntax where I use one line with the for cycle at the end is new to me. Originally I wrote:
def permutationEquation(p): answer = []
for x in sorted(p): answer.append(p.index(p.index(x) + 1) + 1) print(answer)
Seems like cookies are disabled on this browser, please enable them to open this website
Sequence Equation
You are viewing a single comment's thread. Return to all comments →
My solution
def permutationEquation(p): return [p.index(p.index(x) + 1) + 1 for x in sorted(p)]
I am just learning Python, so the syntax where I use one line with the for cycle at the end is new to me. Originally I wrote:
def permutationEquation(p): answer = []