How to get the index of a list?

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!

Index|690x318

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

Capture

3 Likes

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 :

Like this?

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.

1 Like

Nop :confused:
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.

1 Like

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 :

1 Like

@tiagocorradi thank you ! it will help for sure :slight_smile:

If a comment solves your problem, please mark it as solved (and maybe leave a like here and there there)

1 Like

Do you have an idea why it doesn’t work for me?

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

It doesn’t work anyways :confused:

Can you show the warning you’re getting?

Capture

Try Append instead of Add.

Wrong Result :confused:

Capture

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