Best way to sort one list based on another?
|
07-04-2015, 10:40 AM
Post: #1
|
|||
|
|||
Best way to sort one list based on another?
I have two lists
name := { "Bird", "Jordan", "O'Neal" } height := { 2.06, 1.98, 2.16 } and I want to sort the names into height order. What's the best way to do this in HP PPL, please? |
|||
07-04-2015, 02:52 PM
Post: #2
|
|||
|
|||
RE: Best way to sort one list based on another?
I couldn't find any way to do it except the brute force method:
Code:
There is probably a better way, but this at least works. Road |
|||
07-04-2015, 06:51 PM
Post: #3
|
|||
|
|||
RE: Best way to sort one list based on another?
Code:
|
|||
07-04-2015, 08:00 PM
Post: #4
|
|||
|
|||
RE: Best way to sort one list based on another?
There isn't a PPL built-in function to list in using another list as a key.
As others have suggested one can write your own sort function. However, the Prime appears to have built-in buttons that can do something very similar for spreadsheet columns and to three columns of statistical data. And it can turn lists into columns. These built-in features might be of some use if you wanted to avoid writing your own sort function - but they cannot be accessed from the PPL as far as I know. It seems a pity that spreadsheets and statistical apps can do such a sort, but lists and the PPL cannot (or have I missed something?) Perhaps this could be added in a future PPL? Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
07-04-2015, 09:53 PM
Post: #5
|
|||
|
|||
RE: Best way to sort one list based on another?
Okay, here's a quick & dirty effort[1]:
Code: EXPORT name := { "Bird", "Jordan", "O'Neal" }; Call as: SORTB(name, height) [1] It's not perfect - two people with the same height will be sorted by name as well. |
|||
07-05-2015, 06:03 AM
(This post was last modified: 07-05-2015 06:04 AM by Tyann.)
Post: #6
|
|||
|
|||
RE: Best way to sort one list based on another?
Hello
I suggest Code:
SORTM({{5,2,3,1},{100,200,300,400},{"A","B","C","D"}}) return {{1,2,3,5},{400,200,300,100},{"D","B","C","A"}} SORTM({{5,2,3,1},{100,200,300},{"A","B","C","D"}}) return Erreur SORTM({{5,2,3,1},{100,200,300,400},{"A","B","C","D","X","H"}}) return {{1,2,3,5},{400,200,300,100},{"D","B","C","A","X","H"}} Hoping that it will be useful. Sorry for my English (Google traduction) |
|||
07-05-2015, 07:34 AM
Post: #7
|
|||
|
|||
RE: Best way to sort one list based on another? ANSWERED
For those finding this thread in the future, the best answer is here.
|
|||
07-05-2015, 06:27 PM
Post: #8
|
|||
|
|||
RE: Best way to sort one list based on another?
thank you ,nice response
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)