How to get the index of a list?


#1

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


#2

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

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 :


#4

Like this?


#5

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.


#6

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”


#7

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.


#8

Thank you all ! It works thanks to @nick_boyts ’ solution !


#9

@Nick_Boyts has your solution, but here is a python script for it, just to record :


#10

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


#11

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


#12

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


#13

You forgot to indent the 10 an 11 lines in your script. Just select this two lines and press Tab.


#14

if isLevel = True
should be
if isLevel == True


#15

It doesn’t work anyways :confused:


#16

Can you show the warning you’re getting?


#17

Capture


#18

Try Append instead of Add.


#19

Wrong Result :confused:


#20

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