How do I get the last "N" numbers in a list

Still very new to grasshopper and was wondering how I would extract the last 10 integer values from a list of 1000.

Hi @ryanst

To select the last item of a list, you use List Item component with Index number -1.

In order to select the last 10 you need: -1, -2, -3, … etc.

Instead of writing this in a panel manually, you can use the component Series.
Start = 1
Step = 1
Count = 10
This will generate numbers 1, 2, 3, … etc.
All that is left is use the Negative component to convert these numbers to negative.

Use those numbers as the Indexes input for the List Item.

There it is!
thank you for the prompt response @ShynnSup

That depends on what you mean by “last 10”.

Is it always the last N numbers in the list, regardless of magnitude? You could just split the list as shown here:


Last10.gh (9.1 KB)

Is it the largest N numbers? You could sort the list and do the same thing:

1 Like