# there is a shorter way to do this?

Posted 9 years ago
4523 Views
|
2 Replies
|
3 Total Likes
|
 Below expose to you my problem I'm trying to solve, I have this list where I want to sort by area, as show below, but do not put attention in the first element of each tuple. Show my code for you to tell me if there is any way to make this shorter, this is because I will occupy larger lists, any idea is welcome, greetings to all. In[37]:= inter Out[37]= {{3, 60, 50}, {3, 40, 50}, {3, 30, 30}, {1, 62, 61}} In[38]:= area = inter[[;; , 2]]*inter[[;; , 3]] Out[38]= {3000, 2000, 900, 3782} In[39]:= Do[AppendTo[inter[[i]], area[[i]]], {i, 1, Length[area]}] In[40]:= inter Out[40]= {{3, 60, 50, 3000}, {3, 40, 50, 2000}, {3, 30, 30, 900}, {1, 62, 61, 3782}} In[41]:= inter = Sort[inter, #1[[4]] > #2[[4]] &] Out[41]= {{1, 62, 61, 3782}, {3, 60, 50, 3000}, {3, 40, 50, 2000}, {3, 30, 30, 900}} In[42]:= inter = inter[[;; , ;; 3]] Out[42]= {{1, 62, 61}, {3, 60, 50}, {3, 40, 50}, {3, 30, 30}} 
2 Replies
Sort By:
Posted 9 years ago
 Thanks Sandu Ursu,that's what I need, I'm still trying, apparently still working properly
Posted 9 years ago
 I'm not sure, but this might do the work: SortBy[inter, #[[2]]*#[[3]] &] // Reverse