Encode1.gh (2.4 KB)
I want each sublist in a to contain all the elements from x at least once. If an element was missing, it has been replaced with a repeated element from the sublist.
Encode1.gh (2.4 KB)
I want each sublist in a to contain all the elements from x at least once. If an element was missing, it has been replaced with a repeated element from the sublist.
To create a list with a specific number of items from a list of spaces, while ensuring all the spaces are included, you can follow these steps:
By following these steps, you will have a new list with the desired number of items, including all the spaces from the original list.
import ghpythonlib.treehelpers as th
from random import choice, shuffle
# List of available spaces
spaces = ["bathroom", "Entrance", "livingroom", "bedroom", "kitchen", "Terrace"]
# Desired lengths for each collection
lengths = [10, 10, 6, 6]
# List to store the collections
collections = []
# Iterate over each desired length
for n in lengths:
# Create a new collection starting with a copy of available spaces
collection = list(spaces)
# Add random spaces to the collection until desired length is reached
while len(collection) < n:
collection.append(choice(spaces))
shuffle(collection) # Shuffle the collection randomly
collections.append(collection) # Add the collection to the list of collections
# Convert the collections to a tree structure
a = th.list_to_tree(collections)
Setareh.gh (6.4 KB)
Assigned to Scripting category