Hi guys!
I am trying to create an optimized script but I have a problem to extract the index of a list that countains “Level”.
I have tried the string.contains solution and indexOf too but when I run the script the index generated is “-1” and I don’t understand why!
I’m trying to understand what you want to achieve … do you mean something like this?
input = IN[0]
testvalue = IN[1]
output = []
a = 0
for i in input:
if i == testvalue:
output.append(a)
a = a+1
#Assign your output to the OUT variable.
OUT = output
Actually I want to replace and Item At index but the problem is that I can’t have the “List index” that contains “LEVEL”
That’s what I want to achieve :
You’re checking elements against a string. You need to first determine what category the elements are. Then you can replace any Levels with the level name.
Element.Category is from Rhythm.
Nop
I just want the script to give me the index 0 if Level is in “0 List” and 1 if Level is in “1 List”
If you’re trying to replace the levels with their names then a mask is your best option. If you really need the index you can search for lists that contain Levels.
Thank you all ! It works thanks to @nick_boyts ’ solution !
@Nick_Boyts has your solution, but here is a python script for it, just to record :
@tiagocorradi thank you ! it will help for sure
If a comment solves your problem, please mark it as solved (and maybe leave a like here and there there)
You forgot to indent the 10 an 11 lines in your script. Just select this two lines and press Tab.
if isLevel = True
should be
if isLevel == True
Can you show the warning you’re getting?
Try Append instead of Add.
Wrong Result
Check your code again. You must be mistyping something somewhere.
list = IN[0]
test = IN[1]
finalList = []
for index in range(0,len(list)):
level = list[index]
isLevel = False
for item in level:
if item == test:
isLevel = True
if isLevel == True:
finalList.append(index)
OUT = finalList