JOIN LIST AND SUBLIST IN PYTHON ..help

Very good days.
I’m still learning python and now I have the following problem…
How could I join a list with a sublist but make it look like the final result of the image… remember that there will always be a sublist.

Thank you so much


02_JoinList.dyn (8.0 KB)

On my phone e so excuse any typos

list = IN[0] #the flat list from Dynamo
listOfLists = IN[1] # the list of lists from Dynamo
newList = [] # the new list to hold the lists
newList.append(list) # add the flat list to the new list
[newList.append(i) for i in listOfLists] # list comprehension to add each list in the listOfLists to the new list
OUT = newList #return the new list to the Dynamo environment

1 Like

Hi,
here an example


# Carga las bibliotecas de DesignScript y normas de Python.
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

Numbers = ["X","B","3"]
Elements = [["a","b","c","d"],["a","b","c","d"]]
# Insert the Numbers list at the beginning of the Elements list
Elements.insert(0, Numbers)

# Create a new list called Result and iterate over the Elements list,
# converting each sublist to uppercase
Result = [[i.upper() for i in sublist] for sublist in Elements]

# Assign the Result list to the OUT variable
OUT = Result
2 Likes