Yes, understanding lists and trees is essential for complex Grasshopper workflows.
Essentially a list is a flat data structure, a sequence of data items with a certain order that can be altered.
Example:
- apples
- tuna
- cat food
- chocolate
- bread
In pseudo-code, you’d write the same shopping list like this:
["apples", "tuna", "cat food", "chocolate", "bread"]
Or like this:
{"apples", "tuna", "cat food", "chocolate", "bread"}
Don’t worry about the "
! They just mean that the items are text strings, which is relevant in programming.
Now each list items has a numbered position in the list, which can be changed. The position is called index and the list indexing starts at 0 (not 1). "apples"
sits at index 0, "tuna"
at index 1, and so fourth. You can fetch individual items with these indices. An index of 0 gives you the first (i.e. "apples"
), and an index of -1 the last item (i.e. "bread"
) from the list.
Lists can be re-arranged (i.e. Jitter), items deleted (i.e. CullIndex), two or more lists can be merges, etc.
Trees on the other hand can viewed as multidimensional data structures, but they basically work similar to lists.
Example:
- produce
– apples
– salad
- canned goods
– tuna
– beans
– cat food
- dry goods
– chocolate
– granola
- bakery
– bread
Now to represent this multidimensional data in pseudo-code would look similar to this:
{
["apples", "salad"], // produce
["tuna", "beans", "cat food"], // canned goods
["chocolate", "granola"], // dry goods
["bread"] // bakery
}
You can think of this as a nested list, a list of lists, a two-dimensional data tree…
At index or branch {0} we now have produce, at {1} canned goods. At index {0;1} we have salad. Whole branches can be extracted by index or path just like items in a list.
Most other manipulations also still apply.