algorithmic modeling for Rhino
Tags:
You can simply use the Member Index component.
If you still want to write GHPython script then maybe you can loop through the list with enumerate() in order to retrieve all the indexes of True values, then append them to a new list. See attached.
Hi vhoang
I am surprised that there is a simple GH component.
Your code in python is also helpful.
Thank you!!
--
Tomo
as mentioned, enumerate is probably what you are looking for. From a strictly pythonic approach, it would be some variation of this:
index = [] #list to hold the index, named component output
value = [] #list to hold the value, named component output
enumeratedList = list(enumerate(x)) #example to show results of enumerate
for i,j in enumerate(x): #i is first value, j, is second value
if j == y: #set input hint type to string and connect boolean toggle
index.append(i) #append i, (first value) to index list
value.append(j) #append j, (second value) to value list
Thank you!
I thought using the "index" method provided by the list type to get the index of the element. But, only the first index could be extracted.
"enumerate" is useful.
just to add one more python option to the above:
a = [v for v in range(len(x)) if x[v]]
will get it done in a single line. it's not the most readable thing so an explicit loop might be better depending on your purposes, but I am quite fond of the elegance of these list comprehension statements in python.
That is certainly very elegant! Thanks!. I need to brush up on my list comprehension.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by