Best way to sort one list based on another? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Best way to sort one list based on another? (/thread-4294.html) |
Best way to sort one list based on another? - BruceH - 07-04-2015 10:40 AM 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? RE: Best way to sort one list based on another? - roadrunner - 07-04-2015 02:52 PM I couldn't find any way to do it except the brute force method: Code:
[attachment=2265] There is probably a better way, but this at least works. Road RE: Best way to sort one list based on another? - DrD - 07-04-2015 06:51 PM Code:
RE: Best way to sort one list based on another? - StephenG1CMZ - 07-04-2015 08:00 PM 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? RE: Best way to sort one list based on another? - BruceH - 07-04-2015 09:53 PM 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. RE: Best way to sort one list based on another? - Tyann - 07-05-2015 06:03 AM 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) RE: Best way to sort one list based on another? ANSWERED - BruceH - 07-05-2015 07:34 AM For those finding this thread in the future, the best answer is here. RE: Best way to sort one list based on another? - Tyann - 07-05-2015 06:27 PM thank you ,nice response |