Create multiple lists from a List, by using integer values to define the number of items in each new list

Hi all, I’m needing some assistance with list manipulation,

  • I have a master list of values
  • Using this list, some manipulation is done and currently results with a List.Count Node outputting a variable amount of integers (using Levels @@L2).
  • The sum of these integers is equal to the number of items in the master list.

all very simple so far…

What I would like to do is:

  • Create ‘N’ number of lists, where N is the total number of indices in the List.Count node.
  • The contents of each list are items from the master list, retaining the same sequence.
  • The values in the 1st list should be the first ‘X’ number of items, where X = List.Count node’s index 0
  • The values in the 2nd list should be the first ‘Y’ number of items, where Y = List.Count node’s index 1
  • The values in the 3nd list should be the first ‘Z’ number of items, where Z = List.Count node’s index 2
    etc…

To try and explain with an example

Master List (values):
1,2,3,4,5,6,7,8,9,10

List.Count (index : Value)
0 : 2
1 : 5
2 : 3

Desired 1st List output:
1
2

Desired 2nd List output:
3
4
5
6
7

Desired 3rd List output:
8
9
10

Apologies if that’s not the best way to explain the issue, but its the best I could come up with, as I’m not yet that familiar with the different nodes.

@Genexus Chop it:

Hi @Elie.Trad
Yeah I am using List.Chop elsewhere, the problem is I want to create a running sum of each of the lists items with List.Scan, but it doesn’t appear to be working correctly as you can see.

@Genexus what is the end result that you are expecting?

@Elie.Trad
I think this is the correct output.

The problem I have with this, is I have had to manually create the separate Code Block|List.Scan|List.RestOfItems nodes for each of the sub lists.

To example why its a problem, if the numbers 2,3,5 were changed by other parts of the graph to 2,1,2,5 I would have a problem because I don’t have the same nodes to separate out List[3] and so on. Its still 10 items, just now in 4 lists.

I hope that makes sense

Following @Vikram_Subbaiah idea, just search in the forum:

1 Like

I’ve tried replicating that node arrangement but I’m getting some appearance differences in the nodes (perhaps related to my Revit version?) and I’m unsure if Use Levels is active on some of the nodes, when I leave it disabled, I get different values:

@Genexus set Lacing to Shortest:

Makes no difference:


That List.Count node will not change regardless if I enable Use Levels or not.

Can you show a screenshot of this not working? List Levels should give you the correct output.

It seems that my graph must have somehow glitched, I copied out those nodes and pasted into a new graph and it worked fine, so I reopened my original and it started working. Not sure what caused it but at least its working as intended now. Thanks for the assistance.

1 Like