Slice List

../../../../_images/slice_list.svg

Documentation

Slice List.

Slicing is used to remove items from the input list.

Briefly, the slice operation removes values in the input data outside the index range between given start and stop. Step determines which value to keep inside the range. 1: every value, 2: every other value, etc.

In more detail, slicing can be thought of as an operation which generates an index list starting from start, taking steps of length step and finishes at the last index <= stop.

The generated index is list then compared with the indices of the values in the input data (the first value has index 0). Values whose index is contained in the generated index list are kept and the others are removed.

To handle an unknown number of values (normal case), the indices can also be specified relative to the end (last index). “Count stop from the end” is enabled by default for stop, and when enabled, the effective index is: end - stop. “Count start from the end” is also available and can be enabled to treat start in a similar fashion.

Warning

Compared to slicing in Python, this method has some notable changes:

  • Using start > stop to reverse the output is not supported. Consequently strides can not be negative. Should start be larger than stop, the output will be empty.

  • The range is inclusive for both start and stop, meaning that the value that matches the stop index can also be included.

Examples

input:

[‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]

Example 1:

start:

1

stop:

4

step:

1

index:

[1, 2, 3, 4]

output:

[‘b’, ‘c’, ‘d’, ‘e’]

Example 2:

start:

0

stop:

5

step:

2

index:

[0, 2, 4]

output:

[‘a’, ‘c’, ‘e’]

Example 3:

start:

0

stop:

0 (Count stop from the end)

step:

1

index:

[0, 1, 2, 3, 4, 5]

output:

[‘b’, ‘c’, ‘d’, ‘e’, ‘f’]

Example 4:

start:

0

stop:

1 (Count stop from the end)

step:

1

index:

[0, 1, 2, 3, 4, 5]

output:

[‘b’, ‘c’, ‘d’, ‘e’]

Definition

Input ports

data [<a>]

Input List

Output ports

data [<a>]

Output Table

Configuration

Count start from the end (decrement_start)

Count start from the end, when enabled, start is counted backwards from the end (last index).

Count stop from the end (decrement_stop)

Count stop from the end, when enabled, stop is counted backwards from the end (last index).

Start (start)

Start, specifies the start index of the value range.

Step (step)

Step, specifies the step length taken in the value range and determines which values inside of the range to keep.

Stop (stop)

Stop, specifies the stop index of the value range.

Implementation

class node_slice.SliceItemsList[source]