Sorting lists within a list in Python

Question:

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]]
Asked By: user19657580

||

Answers:

Just remove the range

J=[[10, 4, 7], [10, 4],[1,9,8]]
for i in J:
    i.sort()
print(J)

Output:

[[4, 7, 10], [4, 10], [1, 8, 9]]
Answered By: Erastus Nzula
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.