Hello, all!
I am a DesignScript beginner, and I need help rewriting this code without using the replication guides since they do not work in imperative blocks. I wanted to retry this using python but I have little to no experience with it.
Hello, all!
I am a DesignScript beginner, and I need help rewriting this code without using the replication guides since they do not work in imperative blocks. I wanted to retry this using python but I have little to no experience with it.
What is your code trying to do? Seems a List.Flatten will work out better for you as that should do what you’re after directly.
I’m trying to get the first item of each of these sublists, and I want to keep repeating that until there are no more items left in the “rest” list… flattening won’t really achieve the result that I need.
Your intent isn’t clear to me so I’ll try and work though a simple example.
Given a list of sublists [ [1, 2, 3], [4,5,6] ]
Do you want to take the first sublist (1,2,3) and get the first item, then take the second sublist and take the first item from that, resulting in [1,4]. This is best done with List.FirstItem set to @L2 for the input - no imperative code needed.
OR
Do you want to take the first item from the first sublist (1, 2, 3) over and over again until there are no items left in the first sublist, then take the first item out of the second sublist until there are no items left, resulting in [1, 2, 3, 4, 5, 6]. This is best done with List.Flastten, no imperative code needed.
OR
Do you want to do something else entirely?
I’m struggling to describe what I want… you’re close with the first one.
What I’m trying to do is to create a new list, with each sublist in the list consisting of the first item of the input list. I want to take the “rest” list (the “leftover” items after taking the first item), and take the first item of that list as well. I want to keep repeating this operation until there are no items in the “rest” list.
So, if my input list is:
[ [1,2,3], [4,5,6], [7,8,9] ]
I want my output list to be:
[ [1,4,7], [2,5,8], [3,6,9] ]
If its’s just that you could just Transpose the list.
If this is not a solution, please provide a sample input and output to better explain your intent.
I don’t know how this solution escaped me! This is exactly what I want, thank you.
The action you’re after is known as List.Transpose, which @Vikram_Subbaiah illustrated quite well. There might be more to it (i.e. layering in a List.Clean to remove some additional nulls for mismatched list lengths), but you absolutely don’t need to jump into imperative code for it.
While I suppose you will not be trying to rectify your Imperative code for this task, for any future tasks where you’re trying to apply /extract something to multiple nested levels using, consider exploring functions in Design Script.