Sublist manipulation (delete last item)

Hello everybody. I have a list of sublists, and each of these sublists contains anywhere from 3 to 5 items - the number of items varies pretty randomly between sublists. I want to delete the last item from each sublist. How can I do that?

Many thanks,

Idris

Hello,

Have you tried using “List.DropItems” with a negative value?

2015-07-29_09-17-23

Dimitar, you are a genius. Worked like a charm. Can you explain to me why this works, though? Having trouble understanding it.

Thank you!!

Also, is there a way to extract the first item of each sublist and make a list of these first items?

The description of the node is jumbled… If you hover over the “amount” input, you’ll see the explanation that if you use a negative number, the items will be removed from the end of the list.
With “List.Map”, we perform the function to each sub-list in the input list.

Hope that helps.

It does! One last issue. I have one list of 495 points, and I have another list of 495 sublists, and each sublist has 3-6 items. What I want to do is take each point from the first list, and make it the first item of each respective sublist in the second list (in other words, the first item on List A would become the first item of Sublist 1 in List B). All I can think of is the method below, but I’d need a way to combine every two sublists into one. Is there a way to insert items directly into the first spot of sublists? Or is there a way to do this sublist combination method I’m thinking about? Thank you again!

insertfirst

 

 

Hello Idris,

Here you go.

AppendToExistingList

You’ll need to use “List.Combine”, which is very similar to “List.Map” in theory. The only difference being that you can specify an argument for each variable in the function. In your case the function will be “List.AddItemToFront”. It needs two variables to work - an item to be added and a list to perform the action on. In your case each item in listA is the “item” variable and listB is the “list” variable.

2015-07-29_13-28-08

Also note the “Flatten” node. Most functions won’t need it there, “List.AddItemToFront” is an exception due to the way the node works. For example “List.AddItemToEnd” doesn’t need it:

2015-07-29_13-31-18