-6
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]
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0

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]
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61