Insert Lists at Indices of a List

Hey guys,

I have a problem I can t solve at the moment:

I want to convert the data type of various list and their values. Thus I deconstructed the list (list 1) and converted the datatype of the values they contain.

I used a list cycle to have some kind of dummy list where i can replace the indices, but I can t put the deconstrueced list back to its initial state.

I hope you understand the thing I m aiming for :slightly_smiling_face:

Please find attached my definition. Thanks in advance for any help!

180125_DataTypeConversion.dyn (21.8 KB)

Insert can only insert one item into a single list at a time. Giving it multiple elements with multiple indices returns multiple lists.
image
In order to insert multiple indices into a single list you need to use python.

I think what you’re really trying to do is recreate your original list based on object types. You’re better off using a dictionary in this scenario. Your other option is to make a list with your indices [0,4,1,3,2] and another list with your object types (keeping the sublists intact). You should then be able to use GetItemAtIndex to get the particular sublist of object types from your list of indices.

1 Like

@erfajo

Thank`s a lot, this is the direct solution for my problem! I m starting to learn python, still a long way to go - this keeps me motivated.

@Nick_Boyts

Thank you too, as you mentioned dicitionaries - opens up new possibilities, I ll check it out!

Here is a python script shall do this task

# Import necessary modules
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Define the function
def insert_items(original_list, items_to_insert, indices):
    new_list = list(original_list)  # Create a copy of the original list
    for i, item in enumerate(items_to_insert):
        new_list.insert(indices[i], item)
    return new_list

# Get inputs from IN variables
original_list = IN[0]
items_to_insert = IN[1]
indices = IN[2]

# Call the function with the inputs and store the output in OUT variable
OUT = insert_items(original_list, items_to_insert, indices)

1 Like