Duplicate values within a nested list


#1

I have a list containing 40 sublists. Each sublist contains 10 items (say points A-J along a curve). I would like to end up with a list of sublists, where each sublist contains 2 items like this: List [0] contains 10 sublists. Each sublist contains a list of 2 points: list [0] contains points [A,B], list [1] contains points [B,C], list [2] contains points [C,D], etc…

Capture


#2

Against this issue, I am also often. I have found two solutions. For points on a line it is easier:

List_double

My second method is to play with the list actions. It is the much longer way.

If anyone knows an easier way, please post :slight_smile:

But I’m not quite sure if this was your problem ^^


#3

Figured it out:

  1. Created a copy of the list
  2. Using List.RestOfItems, remove first item from one of the lists to offset the values.
  3. Using List.Chop, divide lists into sublists each containing 2 values.
  4. Using List.Join, join lists! This actually returns 2 appended lists of sublists, not laced lists of sublists, but that works for me.

NB: Use List.Map to get access to the sublists and apply each function.

Capture


#4

Thanks Leo!