Previous Up Next

6.39.7  Finding a subsequence or a sublist

The bracket notation used to find elements of sequences and lists can also be used to extract a range of elements. If S is a sequence or list of size n, then S[n1..n2] returns the subsequence or sublist of S consisting of the elements with indices from n1 to n2, where 0 ≤ n1n2 < s (in Xcas syntax mode) or 0 < n1n2s in other syntax modes.


Examples.


For lists, the at command can also be used to get a sublist.

Again, at can not be used for sequences.


Example.
Input:

at([1,2,3,4,5],2..4

Output:


3,4,5


An alternative to using at for finding a sublist is the mid command, which again cannot be used for sequences.


Examples.


Previous Up Next