Python List Output into Grafted Trees

Hello, I’m using Itertools in python to give a series of permutations out. However, its outputting the numbers as sets of strings in a list. I’m wondering if there is a way to make the numbers into a grafted list?

Current python module and output:

Essentially, the output i’m looking for is each set of number- i.e index 0 (1,1,1,7) is actually output as
(0;0)
(0)1
(1)1
(2)1
(3)7

Thanks.

Hi @pwnsaur,

Starting from what you already have, you can probably do this:

from itertools import combinations_with_replacement
from ghpythonlib import treehelpers

combinations = combinations_with_replacement(xrange(x+1), y)

nested_combinations = []

for comb in combinations:
    if sum(comb) == x and comb[0] > 0:
        ncomb = []
        for num in comb:
            ncomb.append([num])
        nested_combinations.append(ncomb)
    
a = treehelpers.list_to_tree(nested_combinations)

Also you should check this out!

What are you going to use that tree with?

If you have other GhPython why not keep the python list as output?