Post Reply 
List Manipulation
05-19-2023, 09:25 PM (This post was last modified: 05-19-2023 09:30 PM by matalog.)
Post: #1
List Manipulation
Is there a way to split a list into 2 or to say that A{}:= B{}(32-64)?

So that List A will now contain the 32,33,34.....64th entry in List B as it's first 32 spaces?

Short of that is there a way to tail(32)? To remove 32 entries from the beginning of a list?

Are there any good List manipulation guides or tutorials?
Find all posts by this user
Quote this message in a reply
05-19-2023, 10:50 PM
Post: #2
RE: List Manipulation
I think you may want the SUPPRESS command. Try the following in HOME:

MAKELIST(X,X,1,64)▶la;
SUPPRESS(la,1,32);
SUPPRESS(la,33,64);

-road
Find all posts by this user
Quote this message in a reply
05-19-2023, 11:03 PM
Post: #3
RE: List Manipulation
list({a,b}) will return a list from element a to b (or up to size(list)):
A:=B({1,32}) should do
Find all posts by this user
Quote this message in a reply
05-19-2023, 11:06 PM
Post: #4
RE: List Manipulation
FYI A, B are not list variables, so define a variable list first or use L1 etc.
Find all posts by this user
Quote this message in a reply
05-19-2023, 11:09 PM (This post was last modified: 05-19-2023 11:10 PM by Didier Lachieze.)
Post: #5
RE: List Manipulation
My comments below are related to Home and PPL, not to CAS which may have other ways to manipulate lists.

(05-19-2023 09:25 PM)matalog Wrote:  Is there a way to split a list into 2 or to say that A{}:= B{}(32-64)?

So that List A will now contain the 32,33,34.....64th entry in List B as it's first 32 spaces?

L1:=L2({32,64})

See page 552 of the manual:

"List references
Suppose L1:={5, "abcde", {1,2,3,4,5}, 11}. L1(1) returns 5 and L1(2) returns "abcde". L1(2, 4) returns 100 (the ASCII code for d) and L1(2,4,1) returns "d". L1({2,4}) returns {"abcde", {1,2,3,4,5},11}, extracting a sublist of all the elements from 2 through 4.
"

One additional thing for list references is about the zero index value:
L1(0) returns the last element of the list
L1(0):=n adds n as a new element at the end of the list

Quote:Short of that is there a way to tail(32)? To remove 32 entries from the beginning of a list?

SUPPRESS(L1,1,32)

Quote:Are there any good List manipulation guides or tutorials?

Nothing I would know, but I may have missed them.
Find all posts by this user
Quote this message in a reply
05-20-2023, 07:10 AM
Post: #6
RE: List Manipulation
You may find some of the list functions here useful.
(The routines in here try to handle edge cases which some of the built-in routines miss).
https://www.hpmuseum.org/forum/thread-94...light=List
It includes a summary of built-in list commands.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
05-21-2023, 11:57 PM
Post: #7
RE: List Manipulation
That's great, thanks guys.
Find all posts by this user
Quote this message in a reply
08-24-2023, 12:39 PM
Post: #8
RE: List Manipulation
I have a list A it is 64 bytes, and I want to remove 1 byte. Is there a quicker way to A:=A({1,63}); to remove the last element?
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)