# Python List Output into Grafted Trees

**URL:** <https://discourse.mcneel.com/t/python-list-output-into-grafted-trees/99461>\
**Category:** Grasshopper\
**Created:** [April 3, 2020, 10:34pm UTC](https://discourse.mcneel.com/t/python-list-output-into-grafted-trees/99461 "2020-04-03T22:34:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![diff-arch](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/diff-arch/32/528268_2.png) [@diff-arch](https://discourse.mcneel.com/u/diff-arch)\
**Post date:** [April 4, 2020, 6:34am UTC](https://discourse.mcneel.com/t/python-list-output-into-grafted-trees/99461/2 "2020-04-04T06:34:38Z")

</div>

Hi @pwnsaur,

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

```python
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)

```

 ![Screenshot 2020-04-04 at 08.31.55](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/5/d/5d6e8023291630ce3b7c4a586ec7187715a11bf7.png)

Also you should check [this](https://discourse.mcneel.com/t/how-to-ask-effective-questions/50034) out!

---

_[View the full topic](https://discourse.mcneel.com/t/python-list-output-into-grafted-trees/99461)._
