Hello everyone!!
I am trying to replace the “sab” string to the value that is directly above it. basically, I want the outcome to be as such:
10
10
10
20
30
30
any feedback will be appreciated. thank you!
Kathir
I am trying to replace the “sab” string to the value that is directly above it. basically, I want the outcome to be as such:
10
10
10
20
30
30
any feedback will be appreciated. thank you!
Kathir
Hi @C3312854,
Try this:
for i,x in enumerate(IN[0]):
if IN[0][i] == IN[1]:
IN[0][i] = IN[0][i-1]
OUT = IN[0]
Hello Shah! Thank you for the help, I will try this and let you know. By the way does this code also work for sub lists? If not please do let me know on how i can modify the code. I have no knowledge on python, and your feedback will be appreciated.
kathir
This should do the trick for sublists.
toNestList = lambda x: x if any(isinstance(i, list) for i in x) else [x]
for sub in toNestList(IN[0]):
for i,x in enumerate(sub):
if sub[i] == IN[1]:
sub[i] = sub[i-1]
OUT = IN[0]
hello shah!
I will try this out and let you know thank you!!
kathir