![]() |
  |
|
4.3.2.2 Example: non-zero integer subsequences Consider a following problem : we are given a list of integers, some of which can be zero. The task is to extract from the list all subsequences of consecutive non - zero elements. For example, this will be our test data set :
The first step in solving this problem will be to use Split (see section 3.10.3) to split the elements into sublists whenever zero is encountered :
We have however captured some zeros into our sublists, so we have to delete them (note the level specification) :
Finally, the previous operation in general produces some number of empty lists from sublists containing a single zero (there can not be sublists containing several zeros - why?). We have now to delete them as well:
We now package all the steps into a function :
Note the use of a named pattern and BlankSequence, to better restrict the argument. Check :
|
|||||||||||||||||