I am trying to insert items to the end of a list at an index. I cannot seam to get it to work though. Sorry if my poor explanation, I am having a hard time trying to explain it.
I have a list with sub list.
List of Index’s
and a list of items to be added. I want one item to be added to to the end of each sub list at of the corresponding index. Right now the whole list of items creates a new sub list.
I think he wants the second list inserted only at certain indexes (Insert node’s index). Don’t have python open right now and I know there is a better way but something like this would work assuming index is always in numerical order:
list1 = IN[0]
list2 = IN[1]
indexes = IN[2]
count = 0
for i in range(len(list1)):
if i == indexes[count]:
list1[i].append(list2[count])
count += 1
or try this:
list1 = IN[0]
list2 = IN[1]
indexes = IN[2]
for i in range(len(indexes)):
list1[indexes[i]].append(list2[i])
I did Vikram’s OOTB solution since it is the most straight forward and done without code. I really like the coded work flows but for others looking for the solution I figured it best.
a = List.GetItemAtIndex(lst,idx);
b = List.AddItemToEnd(itm<1>,a<1>);
c = SetDifference(GetKeys(lst),idx);
d = List.GetItemAtIndex(lst,c);
e = List.Flatten({b,d},1);
f = List.Flatten({idx,c},1);
g = List.SortByKey(e,f)["sorted list"];