Grasshopper

algorithmic modeling for Rhino

Hi there,

I have a list of numbers which I want to replace with particular values, but I am coming into issues. I have been searching the internet and got this far but still getting errors. What I am looking to achieve is to replace every 25 value in a list with 0, 40 with 1, 15 with 2 and 60 with 3. This is what I have so far:

listArray = x

searchList = y

writeList = z

for n, i in enumerate(listArray):

     if i == searchList[0]:

         listArray[n] = writeList[0]

     elif i == searchList[1]:

         listArray[n] = writeList[1]

     elif i == searchList[2]:

         listArray[n] = writeList[2]

     elif i == searchList[3]:

         listArray[n] = writeList[3]

 

a = listArray

Any help appreciated,

Cheers,

Views: 950

Attachments:

Replies to This Discussion

I just got this to work, I right clicked on the x, y, z inputs and changed the 'Access' from Item to List. I've never come across this before, could someone explain for me please or point me in the direction where I can find out?

Cheers!

I am having an issue now where not all numbers are being replaced. Do I need to append the numbers rather than replace them? And if so how would I keep the list structure the same as the input? Any help appreciated :)

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service