Convert to string and then sort.
values = [1, 2, 9, 10, 11, 20, 29, 90, 99, 100]
print(sorted(map(str, values))) # ['1', '10', '100', '11', '2', '20', '29', '9', '90', '99']
The map function applies str to each element of values.
--- Add---
It's better to do it like @digda Haha
print(sorted(values, key=str))
This is much better
© 2024 OneMinuteCode. All rights reserved.