Trouble with nested for loop in Design Script

Hi

I’m having some issues with nested for loops in design script.
I’m fairly certain I’m making some rudimentary mistake.

Can someone please point it out?

Thank you

list1;
[Imperative]
{
	outList=[];
	for(i in 0..List.Count(list1)-1)
	{
		if(i<3)
		{
			for(list1[i] in list1)
			{
				outList=List.AddItemToEnd(1, outList);
			}
		}
	}
	return = outList;
};

I think the problem is with how can I get the sublist of list1 in the 2nd loop.

In Python, you can use

for index, item in enumerate(list1) where the item is being looped.
But in Design script, for(list[i] in list1) does not work.

Why are you using imperative code here? Seems like associative would work fine in this case.

Just to see if I can replicate something from python.

It’s resolved, the issue I had was I kept trying to loop the item of the list, like with enumerate in Python.

But I could’ve just do a simple range and call it later with list[i].

This line is not going to work and it seems ambiguous - possible solution

for(j in list1[i])
    {
         outList=List.AddItemToEnd(1, outList);
    }