How to use List.Transpose Method in Python Script Node Dynamo?

Thanks @jwroelofs for informing the zip(*iterables) method

Here is my code to emulate the result of the dynamo List.Translate node
But I still cannot figure out how to implement dynamo node input list level selection to affect the result
maybe @jacob.small can help with this problem

data = IN[0]

def maxlistdepth(list):
	maxdepth = 0
	for i in list:
		newdepth = len(i)
		if maxdepth < newdepth:
			maxdepth = newdepth
	return maxdepth
	
def addnull(list,maxdepth):
	for i in list:
		while len(i) < maxdepth:
			i.append(None)

maxdlist = maxlistdepth(data)
addnull(data,maxdlist)

OUT = list(zip(*data))

Another solution is to import DSCore Builtin Dynamo Library to use the List.Transpose method

import sys
import clr
clr.AddReference('DSCoreNodes')
from DSCore import List as DList

data = IN[0]
transpose = DList.Transpose(data)

OUT = transpose

The Results are the same

Thanks, @christian.stan for Design.Script solution. I learned from you that CodeBlock can be used to make functions only without any input or output and the function can be used in other CodeBlock

Hereby I attach the .dyn
Python Transpose.dyn (12.8 KB)

1 Like