list1 = [1236,985,150,641876,167]
I want to know how to sorted by sum digits or sorted by last digit in Python.
Output sorted by sum of digits in ascending order:
[150,1236,167,985,641876]
list1 = [1236,985,150,641876,167]
I want to know how to sorted by sum digits or sorted by last digit in Python.
Output sorted by sum of digits in ascending order:
[150,1236,167,985,641876]
Sorting list items considering unit's place. You can try:
list1 = [1236,985,150,641876,167]
sorted(list1, key=lambda n: n%10)
[150, 985, 1236, 641876, 167]