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.
JavaScript
x
4
1
J=[[10, 4, 7], [10, 4],[1,9,8]]
2
for i in range(0,len(J)):
3
J[0].sort()
4
The current output is
JavaScript
1
2
1
[[4, 7, 10], [10, 4], [1, 9, 8]]
2
The expected output is
JavaScript
1
2
1
[[4, 7, 10], [4, 10], [1, 8, 9]]
2
Advertisement
Answer
Just remove the range
JavaScript
1
5
1
J=[[10, 4, 7], [10, 4],[1,9,8]]
2
for i in J:
3
i.sort()
4
print(J)
5
Output:
JavaScript
1
2
1
[[4, 7, 10], [4, 10], [1, 8, 9]]
2