Sort Associations by its Values (which are nested lists)Sort lists according to the order of anotherGrouping...

Necessity of tenure for lifetime academic research

Why is there no Disney logo in MCU movies?

Cheap oscilloscope showing 16 MHz square wave

Rapid change in character

'spazieren' - walking in a silly and affected manner?

Small RAM 4 KB on the early Apple II?

Why do presidential pardons exist in a country having a clear separation of powers?

What is the practical impact of using System.Random which is not cryptographically random?

math mode in ticks ( tikzpicture )

Which is the correct version of Mussorgsky's Pictures at an Exhibition?

Did the Apollo Guidance Computer really use 60% of the world's ICs in 1963?

Journal published a paper, ignoring my objections as a referee

Is it possible for a person to be tricked into becoming a lich?

Is Borg adaptation only temporary?

Can I leave a large suitcase at TPE during a 4-hour layover, and pick it up 4.5 days later when I come back to TPE on my way to Taipei downtown?

How do I get my neighbour to stop disturbing with loud music?

Under GDPR, can I give permission once to allow everyone to store and process my data?

Is this homebrew "Faerie Fire Grenade" unbalanced?

Why did I get UK entry stamps in my British passport?

Why does the U.S. military maintain their own weather satellites?

Why haven't the British protested Brexit as ardently like Hong Kongers protest?

What was Captain Marvel supposed to do once she reached her destination?

I was reported to HR as being a satan worshiper

IList<T> implementation



Sort Associations by its Values (which are nested lists)


Sort lists according to the order of anotherGrouping Nested Lists Based on Differing Values of Single ElementConditional combining of nested listsCreate lists for all nested lists, all nested list lengthsCross-Rearranging parts of nested lists inside list of associationsSelect several values in nested associationsHow to extract the first element in nested listsTurns nested Lists into nested Associations, ReplaceAll for list vs ReplacsAll for associationHow to delete certain lists from a nested list?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







4












$begingroup$


I have associations where the values are nested lists:



assoclist= <|KeyA -> {{a,b,2},{c,d,4},{e,f,3}}, 
KeyB -> {{a,b,1},{c,d,4},{e,f,6}}, KeyC -> {{a,b,2},{c,d,6},{e,f,9}}|>;


Now I need to sort the associations by the total sum of the third elements (here the numbers) in each list so that Key C comes first (total sum = 17), than Key B (11) and Key A (9).



How can I do this?










share|improve this question









$endgroup$










  • 4




    $begingroup$
    SortBy[assoclist, -Total[#[[All, 3]]]&]? (Or use ReverseSortBy and get rid of the minus sign)
    $endgroup$
    – Sjoerd Smit
    14 hours ago












  • $begingroup$
    @SjoerdSmit: I have tried this before but it did not work. It must have been a typing error or so. However now it works perfectly, thx!
    $endgroup$
    – M.A.
    13 hours ago




















4












$begingroup$


I have associations where the values are nested lists:



assoclist= <|KeyA -> {{a,b,2},{c,d,4},{e,f,3}}, 
KeyB -> {{a,b,1},{c,d,4},{e,f,6}}, KeyC -> {{a,b,2},{c,d,6},{e,f,9}}|>;


Now I need to sort the associations by the total sum of the third elements (here the numbers) in each list so that Key C comes first (total sum = 17), than Key B (11) and Key A (9).



How can I do this?










share|improve this question









$endgroup$










  • 4




    $begingroup$
    SortBy[assoclist, -Total[#[[All, 3]]]&]? (Or use ReverseSortBy and get rid of the minus sign)
    $endgroup$
    – Sjoerd Smit
    14 hours ago












  • $begingroup$
    @SjoerdSmit: I have tried this before but it did not work. It must have been a typing error or so. However now it works perfectly, thx!
    $endgroup$
    – M.A.
    13 hours ago
















4












4








4





$begingroup$


I have associations where the values are nested lists:



assoclist= <|KeyA -> {{a,b,2},{c,d,4},{e,f,3}}, 
KeyB -> {{a,b,1},{c,d,4},{e,f,6}}, KeyC -> {{a,b,2},{c,d,6},{e,f,9}}|>;


Now I need to sort the associations by the total sum of the third elements (here the numbers) in each list so that Key C comes first (total sum = 17), than Key B (11) and Key A (9).



How can I do this?










share|improve this question









$endgroup$




I have associations where the values are nested lists:



assoclist= <|KeyA -> {{a,b,2},{c,d,4},{e,f,3}}, 
KeyB -> {{a,b,1},{c,d,4},{e,f,6}}, KeyC -> {{a,b,2},{c,d,6},{e,f,9}}|>;


Now I need to sort the associations by the total sum of the third elements (here the numbers) in each list so that Key C comes first (total sum = 17), than Key B (11) and Key A (9).



How can I do this?







list-manipulation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 14 hours ago









M.A.M.A.

1238 bronze badges




1238 bronze badges











  • 4




    $begingroup$
    SortBy[assoclist, -Total[#[[All, 3]]]&]? (Or use ReverseSortBy and get rid of the minus sign)
    $endgroup$
    – Sjoerd Smit
    14 hours ago












  • $begingroup$
    @SjoerdSmit: I have tried this before but it did not work. It must have been a typing error or so. However now it works perfectly, thx!
    $endgroup$
    – M.A.
    13 hours ago
















  • 4




    $begingroup$
    SortBy[assoclist, -Total[#[[All, 3]]]&]? (Or use ReverseSortBy and get rid of the minus sign)
    $endgroup$
    – Sjoerd Smit
    14 hours ago












  • $begingroup$
    @SjoerdSmit: I have tried this before but it did not work. It must have been a typing error or so. However now it works perfectly, thx!
    $endgroup$
    – M.A.
    13 hours ago










4




4




$begingroup$
SortBy[assoclist, -Total[#[[All, 3]]]&]? (Or use ReverseSortBy and get rid of the minus sign)
$endgroup$
– Sjoerd Smit
14 hours ago






$begingroup$
SortBy[assoclist, -Total[#[[All, 3]]]&]? (Or use ReverseSortBy and get rid of the minus sign)
$endgroup$
– Sjoerd Smit
14 hours ago














$begingroup$
@SjoerdSmit: I have tried this before but it did not work. It must have been a typing error or so. However now it works perfectly, thx!
$endgroup$
– M.A.
13 hours ago






$begingroup$
@SjoerdSmit: I have tried this before but it did not work. It must have been a typing error or so. However now it works perfectly, thx!
$endgroup$
– M.A.
13 hours ago












3 Answers
3






active

oldest

votes


















4













$begingroup$

You may use ReverseSortBy with Total and Composition.



ReverseSortBy[Last@*Total]@assoclist


Hope this helps.






share|improve this answer









$endgroup$















  • $begingroup$
    Beautiful use of the Wolfram Language. The absence of specific list indices is very nice. It is also easily extended by changing Last or Total as needed.
    $endgroup$
    – Lee
    2 hours ago



















2













$begingroup$

E.g:



assoclist[[Reverse[Ordering[Total[assoclist[[All, All, 3]]]]]]]





share|improve this answer









$endgroup$























    1













    $begingroup$

    With Transpose:



    assoclist // 
    Map[Transpose] //
    ReverseSortBy[Total@*Last] //
    Map[Transpose]





    share|improve this answer









    $endgroup$


















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "387"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f204556%2fsort-associations-by-its-values-which-are-nested-lists%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4













      $begingroup$

      You may use ReverseSortBy with Total and Composition.



      ReverseSortBy[Last@*Total]@assoclist


      Hope this helps.






      share|improve this answer









      $endgroup$















      • $begingroup$
        Beautiful use of the Wolfram Language. The absence of specific list indices is very nice. It is also easily extended by changing Last or Total as needed.
        $endgroup$
        – Lee
        2 hours ago
















      4













      $begingroup$

      You may use ReverseSortBy with Total and Composition.



      ReverseSortBy[Last@*Total]@assoclist


      Hope this helps.






      share|improve this answer









      $endgroup$















      • $begingroup$
        Beautiful use of the Wolfram Language. The absence of specific list indices is very nice. It is also easily extended by changing Last or Total as needed.
        $endgroup$
        – Lee
        2 hours ago














      4














      4










      4







      $begingroup$

      You may use ReverseSortBy with Total and Composition.



      ReverseSortBy[Last@*Total]@assoclist


      Hope this helps.






      share|improve this answer









      $endgroup$



      You may use ReverseSortBy with Total and Composition.



      ReverseSortBy[Last@*Total]@assoclist


      Hope this helps.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered 5 hours ago









      EdmundEdmund

      27.4k3 gold badges30 silver badges103 bronze badges




      27.4k3 gold badges30 silver badges103 bronze badges















      • $begingroup$
        Beautiful use of the Wolfram Language. The absence of specific list indices is very nice. It is also easily extended by changing Last or Total as needed.
        $endgroup$
        – Lee
        2 hours ago


















      • $begingroup$
        Beautiful use of the Wolfram Language. The absence of specific list indices is very nice. It is also easily extended by changing Last or Total as needed.
        $endgroup$
        – Lee
        2 hours ago
















      $begingroup$
      Beautiful use of the Wolfram Language. The absence of specific list indices is very nice. It is also easily extended by changing Last or Total as needed.
      $endgroup$
      – Lee
      2 hours ago




      $begingroup$
      Beautiful use of the Wolfram Language. The absence of specific list indices is very nice. It is also easily extended by changing Last or Total as needed.
      $endgroup$
      – Lee
      2 hours ago













      2













      $begingroup$

      E.g:



      assoclist[[Reverse[Ordering[Total[assoclist[[All, All, 3]]]]]]]





      share|improve this answer









      $endgroup$




















        2













        $begingroup$

        E.g:



        assoclist[[Reverse[Ordering[Total[assoclist[[All, All, 3]]]]]]]





        share|improve this answer









        $endgroup$


















          2














          2










          2







          $begingroup$

          E.g:



          assoclist[[Reverse[Ordering[Total[assoclist[[All, All, 3]]]]]]]





          share|improve this answer









          $endgroup$



          E.g:



          assoclist[[Reverse[Ordering[Total[assoclist[[All, All, 3]]]]]]]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 13 hours ago









          CoolwaterCoolwater

          16.2k3 gold badges25 silver badges54 bronze badges




          16.2k3 gold badges25 silver badges54 bronze badges


























              1













              $begingroup$

              With Transpose:



              assoclist // 
              Map[Transpose] //
              ReverseSortBy[Total@*Last] //
              Map[Transpose]





              share|improve this answer









              $endgroup$




















                1













                $begingroup$

                With Transpose:



                assoclist // 
                Map[Transpose] //
                ReverseSortBy[Total@*Last] //
                Map[Transpose]





                share|improve this answer









                $endgroup$


















                  1














                  1










                  1







                  $begingroup$

                  With Transpose:



                  assoclist // 
                  Map[Transpose] //
                  ReverseSortBy[Total@*Last] //
                  Map[Transpose]





                  share|improve this answer









                  $endgroup$



                  With Transpose:



                  assoclist // 
                  Map[Transpose] //
                  ReverseSortBy[Total@*Last] //
                  Map[Transpose]






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 5 hours ago









                  sakrasakra

                  3,15314 silver badges29 bronze badges




                  3,15314 silver badges29 bronze badges

































                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Mathematica Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f204556%2fsort-associations-by-its-values-which-are-nested-lists%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

                      The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

                      Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...