How to sort sum digits from the following list [closed]
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]
python list sorting sum digits
closed as unclear what you're asking by U9-Forward, James K Polk, RoadRunner, eyllanesc, Sandeep Kadapa Nov 12 '18 at 5:01
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 2 more comments
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]
python list sorting sum digits
closed as unclear what you're asking by U9-Forward, James K Polk, RoadRunner, eyllanesc, Sandeep Kadapa Nov 12 '18 at 5:01
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
2
Unclear what you're asking, and way too broad, for noting.
– U9-Forward
Nov 12 '18 at 4:54
So....What output are you expecting here? Where is your attempt? Please provide an MCVE.
– RoadRunner
Nov 12 '18 at 4:57
[output] Sorted by sum of digits in ascending order: [150,1236,167,985,641876]
– Pluvialis Pulchritudo
Nov 12 '18 at 4:58
@PluvialisPulchritudo Usesorted(list1, key = lambda x: sum([int(i) for i in str(x)]))
– Sandeep Kadapa
Nov 12 '18 at 5:08
Orsorted(list1, key = lambda x: sum(map(int,str(x))))
– Sandeep Kadapa
Nov 12 '18 at 5:10
|
show 2 more comments
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]
python list sorting sum digits
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]
python list sorting sum digits
python list sorting sum digits
edited Nov 12 '18 at 7:50
martineau
66.1k989178
66.1k989178
asked Nov 12 '18 at 4:54
Pluvialis PulchritudoPluvialis Pulchritudo
12
12
closed as unclear what you're asking by U9-Forward, James K Polk, RoadRunner, eyllanesc, Sandeep Kadapa Nov 12 '18 at 5:01
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by U9-Forward, James K Polk, RoadRunner, eyllanesc, Sandeep Kadapa Nov 12 '18 at 5:01
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
2
Unclear what you're asking, and way too broad, for noting.
– U9-Forward
Nov 12 '18 at 4:54
So....What output are you expecting here? Where is your attempt? Please provide an MCVE.
– RoadRunner
Nov 12 '18 at 4:57
[output] Sorted by sum of digits in ascending order: [150,1236,167,985,641876]
– Pluvialis Pulchritudo
Nov 12 '18 at 4:58
@PluvialisPulchritudo Usesorted(list1, key = lambda x: sum([int(i) for i in str(x)]))
– Sandeep Kadapa
Nov 12 '18 at 5:08
Orsorted(list1, key = lambda x: sum(map(int,str(x))))
– Sandeep Kadapa
Nov 12 '18 at 5:10
|
show 2 more comments
2
Unclear what you're asking, and way too broad, for noting.
– U9-Forward
Nov 12 '18 at 4:54
So....What output are you expecting here? Where is your attempt? Please provide an MCVE.
– RoadRunner
Nov 12 '18 at 4:57
[output] Sorted by sum of digits in ascending order: [150,1236,167,985,641876]
– Pluvialis Pulchritudo
Nov 12 '18 at 4:58
@PluvialisPulchritudo Usesorted(list1, key = lambda x: sum([int(i) for i in str(x)]))
– Sandeep Kadapa
Nov 12 '18 at 5:08
Orsorted(list1, key = lambda x: sum(map(int,str(x))))
– Sandeep Kadapa
Nov 12 '18 at 5:10
2
2
Unclear what you're asking, and way too broad, for noting.
– U9-Forward
Nov 12 '18 at 4:54
Unclear what you're asking, and way too broad, for noting.
– U9-Forward
Nov 12 '18 at 4:54
So....What output are you expecting here? Where is your attempt? Please provide an MCVE.
– RoadRunner
Nov 12 '18 at 4:57
So....What output are you expecting here? Where is your attempt? Please provide an MCVE.
– RoadRunner
Nov 12 '18 at 4:57
[output] Sorted by sum of digits in ascending order: [150,1236,167,985,641876]
– Pluvialis Pulchritudo
Nov 12 '18 at 4:58
[output] Sorted by sum of digits in ascending order: [150,1236,167,985,641876]
– Pluvialis Pulchritudo
Nov 12 '18 at 4:58
@PluvialisPulchritudo Use
sorted(list1, key = lambda x: sum([int(i) for i in str(x)]))
– Sandeep Kadapa
Nov 12 '18 at 5:08
@PluvialisPulchritudo Use
sorted(list1, key = lambda x: sum([int(i) for i in str(x)]))
– Sandeep Kadapa
Nov 12 '18 at 5:08
Or
sorted(list1, key = lambda x: sum(map(int,str(x))))
– Sandeep Kadapa
Nov 12 '18 at 5:10
Or
sorted(list1, key = lambda x: sum(map(int,str(x))))
– Sandeep Kadapa
Nov 12 '18 at 5:10
|
show 2 more comments
1 Answer
1
active
oldest
votes
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]
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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]
add a comment |
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]
add a comment |
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]
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]
answered Nov 12 '18 at 4:58
Harsha BHarsha B
2,55521733
2,55521733
add a comment |
add a comment |
2
Unclear what you're asking, and way too broad, for noting.
– U9-Forward
Nov 12 '18 at 4:54
So....What output are you expecting here? Where is your attempt? Please provide an MCVE.
– RoadRunner
Nov 12 '18 at 4:57
[output] Sorted by sum of digits in ascending order: [150,1236,167,985,641876]
– Pluvialis Pulchritudo
Nov 12 '18 at 4:58
@PluvialisPulchritudo Use
sorted(list1, key = lambda x: sum([int(i) for i in str(x)]))
– Sandeep Kadapa
Nov 12 '18 at 5:08
Or
sorted(list1, key = lambda x: sum(map(int,str(x))))
– Sandeep Kadapa
Nov 12 '18 at 5:10