Grasshopper

algorithmic modeling for Rhino

Hello, 

I have a question about python lists. I want to have a script that automatically creates new lists with values. For instance a list may contain 5 values, after that automatically a new list is created with the other values. If this list contains also 5 values a new list must be created, and so forth till all values are stored in lists.

Does somebody has a solution, thanks in advance

Roman

Views: 633

Replies to This Discussion

Are you trying to create a list of 5 random values or are you trying to take a large list of existing values and pop 5 values into a new list until it reaches the end? It's hard to offer a good solution without knowing what your data set is. Since it is very difficult to dynamically create new variables within Python (many people suggest using a dictionary as a possible method), you're probably better off taking your original list of values, partitioning it in Grasshopper, and converting the data tree into a list of lists within python. Giulio Piacento has a good method of doing this (including a way to convert the list of lists back into a GH data tree): https://gist.github.com/piac/ef91ac83cb5ee92a1294

I am trying to take a large list of existing values and pop 5 values into a new list until it reaches the end of the large list. So for instance if the large list consist 20 values, 4 list have to be created with each 5 values (list #1 value 1-5; list #2 value 6-10 etc.)

unless you know explicitly how many lists you will result in (if you do you could declare and initialize the lists you will then fill). If it is not a specific amount of lists that will be created then what you are describing is a data tree. Maybe this will help: https://gist.github.com/bengolder/1974640

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service