algorithmic modeling for Rhino
Hi all,
I have a seemingly simple problem, but have been unable to find a solution. I have a list of 4918 items, all of which are strings (either "A," "B," or "C"). I'd like to convert this list into a list of integers of "1," "2," or "3," where all items that are "A" become 1, "B" become 2, etc. I will then associate these values with an accompanying list of lines.
Below is an image to help clarify. I've also attached the script. (Note: I left the GHPython component empty after several failed attempts at case conversion.)
Thanks in advance for your help.
Cheers,
/SPM
Tags:
Replies are closed for this discussion.
Hi Stephen,
You can add an integer values to a new list based on values from the strList:
a = []
for item in strList:
if item == "A":
newItem = 1
elif item == "B":
newItem = 2
else:
newItem = 3
a.append(newItem)
What went wrong at your place?
Hi Djordje,
Thanks for the quick reply and for the code. I'm not sure what happened, to tell you the truth. I tried a very similar approach, but attempted to create three separate lists (one for each item type), but it didn't work out.
It makes more sense to create one master list then create sublists using another conditional loop.
Thanks again,
/SPM
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
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by