I’m new on Dynamo Phyton Scripting.So any help will be appreciated.
I have a python script that creates pairs of all possible combinations from a list. I would like to implement it into Dynamo. Not sure how???
Phyton Script  How to use it on Dynamo
gbardales
#1
Gui_Talarico
#2
You can use that exact same code inside a python node, and only change how you take in the input values
Have you tried it?
If you haven’t done any dynamo/python at all, take a look at Dynamo Primer’s intro to Python Node:
http://dynamoprimer.com/en/09_CustomNodes/94_Python.html
gbardales
#3

Please paste your code as text, instead of an image, if you’d like it to be reviewed. (Use the preformatted text option )

You could try Dynamo’s builtin “Combinations” node as an alternative:
gbardales
#5
ok.
I did try the List.Combinations node but I did not get what I needed.
Thanks for the help.
import clr clr.AddReference('ProtoGeometry') from Autodesk.DesignScript.Geometry import * #The inputs to this node will be stored as a list in the IN variables. dataEnteringNode = IN stringlist = IN[0] import itertools def generate_groups(lst, n): if not lst: yield [] else: for group in (((lst[0],) + xs) for xs in itertools.combinations(lst[1:], n1)): for groups in generate_groups([x for x in lst if x not in group], n): yield [group] + groups stringlist.append(list(generate_groups([stringlist], 2))) #Assign your output to the OUT variable. OUT = stringlist
The problem arises from the fact that you’re wrapping your input list in another list when you’re calling the function:
generate_groups(**[**stringlist], 2)))
1 Like
This should do it:
stringlist = IN[0]
import itertools
def generate_groups(lst, n):
if not lst:
yield []
else:
for group in (((lst[0],) + xs) for xs in itertools.combinations(lst[1:], n1)):
for groups in generate_groups([x for x in lst if x not in group], n):
yield [group] + groups
OUT = generate_groups(stringlist, 2)
2 Likes
Python Nodes Basics