I have a list J consisting of lists. I am trying to sort elements of each list in ascending order. I present the current and expected outputs.
J=[[10, 4, 7], [10, 4],[1,9,8]]
for i in range(0,len(J)):
J[0].sort()
The current output is
[[4, 7, 10], [10, 4], [1, 9, 8]]
The expected output is
[[4, 7, 10], [4, 10], [1, 8, 9]]
J[i].sort()inside the loop rather thanJ[0].sort().J[0]i times.for li in J: li.sort()[sorted(l) for l in J]or[l for l in J if l.sort() is None]. Check the following URL for more details: docs.python.org/3/howto/sorting.html