Replacing the last item in a nested list

Good evening to everyone!
I am pretty new to dynamo, I am growing fast as I am a grasshopper user but some operations (that in GH are quite simple) in this new workspace are just freakin’ me out :smiley:
I have a nested list, the sub-lists have different lengths (from 0 to 5 items).
I need to replace the last item in each sub-list with a new value, that is different in each sub-list.

I already use some packages but I couldn’t find in any of them a node that could do that.

Thanks to everyone in advance.

List.DropLastItem is from Clockwork:

Thank you so much! I’m using clockwork but I never had the chance to use that node!

Now my problem is different: in that nested list I have to choose several items (one for each sub-list, with different index). I have the list of the index of the items I want to extract but I don’t know how to use it!
I’ve tried the list.map, I wrote it in the code block form (x[y][z]) but the result is not what I need.

Thanks again for your precious help!

Can you send a screenshot?
If you have the indices, you can use List.GetItemAtIndex like so:

And if you have the items values, you can use List.AllIndicesOf or IndexOf

1 Like

Unfortunately now I don’t have the file with me, I’ll post a screenshot asap.
Thanks for your example, but my problem is slightly different: in your code you pick the second and the third item from each sub-list.
In my code the items I need to pick in the sub-lists have different indices! I have the list of the indices (one for each sub-list), I tried with the List.Map but it was useless.

Thanks again, when I open the file I will post some screenshots.

Sorry for the late reply.
That’s exactly what I was looking for, thank you very much.