Hp prime list function - indexing into a list « Next Oldest | Next Newest »

 ▼ Andy B (Australia) Junior Member Posts: 15 Threads: 3 Joined: Aug 2013 10-06-2013, 09:30 AM I cannot figure out how to iterate through a list extracting individual items. The POS function searches a list for a particular value but I don't want that - I want to get the exact 1st, 2nd etc. items of a list. I'm a bit surprised such a function doesn't exist? I mean, if you think of a list as an array, there seems no way to be able to get to item 1 or item 2 etc. which you would think are fundamental operations. Am I missing something? ▼ Han Senior Member Posts: 709 Threads: 104 Joined: Nov 2005 10-06-2013, 09:32 AM Quote: I cannot figure out how to iterate through a list extracting individual items. The POS function searches a list for a particular value but I don't want that - I want to get the exact 1st, 2nd etc. items of a list. I'm a bit surprised such a function doesn't exist? I mean, if you think of a list as an array, there seems no way to be able to get to item 1 or item 2 etc. which you would think are fundamental operations. Am I missing something? listname(pos) -- an example using the built-in list name L1 would be L1(2) to get the second item in the list. ▼ Tim Wessman Posting Freak Posts: 1,278 Threads: 44 Joined: Jul 2007 10-06-2013, 10:43 AM Also, L1(1,2,3) would access "4" in this list: {{1,{2,3,4}},5}. For a matrix, M1(3,2) would access item in 3rd row, 2nd col. Storage also functions similarly. TW Edited: 6 Oct 2013, 10:44 a.m. ▼ cyrille de Brébisson Member Posts: 193 Threads: 10 Joined: Mar 2008 10-07-2013, 01:41 AM Quote: Also, L1(1,2,3) would access "4" in this list: {{1,{2,3,4}},5}. For a matrix, M1(3,2) would access item in 3rd row, 2nd col. Storage also functions similarly. and of course it also works the other way around: L1(1):= value changes the first value of L1. L1(1,2,3):=v does as you would expect... L1(10):=v if L1 is of size <10 will increase the size as needed. L1(0):= val will ADD val at the end of the list (so you do not have to do L1(SIZE(L1)+1):= val cyrille

 Possibly Related Threads... Thread Author Replies Views Last Post HP50g: Writing a function that returns a function Chris de Castro 2 448 12-10-2013, 06:49 PM Last Post: Han IFERR function on HP Prime Mic 2 381 12-02-2013, 01:33 AM Last Post: cyrille de Brébisson Milestones:List of IEEE Milestones -> HP-35 AlbertTocarLoseggs 4 429 11-27-2013, 08:52 AM Last Post: Massimo Gnerucci (Italy) HP Prime: Dirichlet's eta function recognized but not numerically evaluated Helge Gabert 0 219 11-16-2013, 03:41 PM Last Post: Helge Gabert HP-Prime : Extracting elements from a list in RPN Miguel Toro 0 326 11-15-2013, 06:44 PM Last Post: Miguel Toro Possible bug with sqrt function in the HP prime Michael de Estrada 6 487 11-15-2013, 12:49 PM Last Post: Michael de Estrada [HP-Prime] Picking elements from a List in a program Jean-Michel 3 396 11-15-2013, 04:16 AM Last Post: dg1969 Hp PRIME - how to send a list to the connectivity Kit giancarlo 1 303 11-10-2013, 11:50 AM Last Post: Tim Wessman How do I decompose a list with the HP Prime. Hal Bitton in Boise 4 410 11-08-2013, 02:07 PM Last Post: Patrice HP-41 MCODE: The Last Function - at last! Ángel Martin 0 226 11-08-2013, 05:11 AM Last Post: Ángel Martin

Forum Jump: