How to sort sum digits from the following list [closed]










-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]









share|improve this 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 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















-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]









share|improve this 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 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













-6












-6








-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]









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • 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







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












1 Answer
1






active

oldest

votes


















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]





share|improve this answer



























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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]





    share|improve this answer

























      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]





      share|improve this answer























        0












        0








        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]





        share|improve this answer












        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]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 4:58









        Harsha BHarsha B

        2,55521733




        2,55521733













            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo