Order by sum of digits X35790


Statement
 

pdf   zip

Write a function @sum_of_digits_sorted(f)@ that provided a list of non negative integers ff returns a list gg with the very same numbers in ff. Numbers in gg must appear in increasing sum of digits. For instance, if 5656 and 21312131 are numbers in ff, number 21312131 will appear before 5656 in gg because the sum of digits of 21312131 (sum is 7) is less the sum of digits of 5656 (sum is 11). Numbers of the same sum of digits must appear in the usual increasing order.

Sample session

Sample session
>>> sum_of_digits_sorted([56, 2131])
[2131, 56]
>>> sum_of_digits_sorted([313, 44, 36, 11111, 35, 26, 7])
[11111, 7, 313, 26, 35, 44, 36]
>>> sum_of_digits_sorted([9, 53, 511, 4000, 10001, 45])
[10001, 4000, 511, 53, 9, 45]
Information
Author
ProAl
Language
English
Official solutions
Python
User solutions
Python