I have a an element k and list of lists which I named as A . I have to sort elements in A using sorted function based on k'th element in A .
Ex :
k=1
A=[[10,20,30],[100,5,300]]
Output should be
[[100,5,300],[10,20,30]]
I can do this easily using below code .
def mysort(x):
return (x[k])
k=1
A=[[10,20,30],[100,5,300]]
print(sorted(A,key=mysort))
But what I am asking here is I want to pass the variable k in to function mysort .