HI Everybody,
I’m trying to replace certain indexes of a list with new items but I can’t get it to work.
See below for the code and attached images.
def customreplace2(List_A:var,indexes:var,items:var)
{
return =[Imperative]
{
sum=0;
sum1=0;
lst={};
for (i in List_A)
{
if (Contains(indexes,sum))
{
lst[sum]=items[sum1];
sum1=sum1+1;
}
else
{
lst[sum]=i;
}
sum=sum+1;
}
}
};
customreplace2(List_A,Indexes,Items);
Hi Salvatore,
You’re missing the return statement in the imperative block:
You can possibly streamline the code a bit:
def customreplace2(l1:var[],ind1:var[],itm1:var[])
{return =[Imperative]{
for (i in GetKeys(ind1) )
{
l1[ind1[i] ] = itm1[i];
}
return = l1;
}};
customreplace2(List_A,Indexes,Items);
3 Likes
def MulRep(lst:var[]..[],idx:var[]..[],itm:var[]..[])
{
return=[Imperative]
{
c=0;
for (i in idx)
{
lst=List.ReplaceItemAtIndex(lst,i,itm[c]);
c=c+1;
}
return=lst;
}
};
3 Likes
Kulkul
4
Hi Salvatore,
Here is another possible way using custom node “List.ReplaceItemAtIndex” from clockwork package.
4 Likes
Thanks Everybody:grinning:
1 Like
Daan
6
Hey Vikram! I just want to say thank you for this script 
1 Like