S
S
swyt2021-12-23 08:21:23
Python
swyt, 2021-12-23 08:21:23

How to sort numbers in correct order?

There are different numbers, when sorted by the sort() method, the numbers are sorted in the order "1, 10, 11, 2, 20, 21, etc."
How to bring them into the form "1, 2, 10, 11, etc."?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
desaki, 2021-12-23
@swyt

Perhaps this article will help you: link
The article talks about the sort()
method. Most likely, you are doing something wrong. I'll show an example:

Если у вас список состоит из чисел, то вывод будет следующим:
number = [1, 10, 5, 11, 2, 4, 20, 21]
number.sort()
Вывод: [1, 2, 4, 5, 10, 11, 20, 21]

Но, если у вас список такой, то вывод будет уже другим:
number = ['1', '10', '5', '11', '2', '4', '20', '21']
number.sort()
Вывод: ['1', '10', '11', '2', '20', '21', '4', '5']

I think you understand what your mistake was

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question