Wrong output when using itertools module

Hello, I’m trying to use itertools product to generate a list where on the first place is any value from first sublist, on the second - from second, etc.
So, a couple of examples if I had this list: [[‘a’, ‘b’, ‘c’], [‘d’, ‘e’], [‘1’, ‘2’]]

[‘a’, ‘d’, ‘1’]
[‘b’, ‘d’, ‘1’]
[‘c’, ‘d’, ‘1’]
[‘a’, ‘e’, ‘1’]
[‘a’, ‘e’, ‘2’]
[‘b’, ‘e’, ‘1’]
[‘b’, ‘e’, ‘2’]

Here is my current code:

As you can see, the combinations output comes as an “IronPython.Modules…”. Any suggestions?
Thanks!
Luis

Do you maybe need the list.combine node?

https://dictionary.dynamobim.com/2/#/List/Match/Action/Combine

or do you want to create all possible combinations from your input sublists?

Then i would recommend List.Combinations / List.Count < on your sublists

Hi Daan, I was using the list.combine node, however I need to create memory dumps for the code to work, otherwise the code can go way above 32GB of RAM usage and crash my Dynamo. Thats why I was using python: to be able to delete variables after using them.

Okay but what output do you need and what is your input? I am trying to figure out what you are trying to do :slight_smile:

Please post the dyn as troubleshooting based on this small code snippet is more difficult than need be.

My initial input is a list of surfaces.
I then divide that list in several sublists of “n” length. In the previous print case, the length is 3.
Afterwards, I want to create all possible combinations of items in the new list, without combining items from the same sublist.
As stated in the first example:

If I had this list: [[‘a’, ‘b’, ‘c’], [‘d’, ‘e’], [‘1’, ‘2’]]
I wanted to get the following combinations:

[‘a’, ‘d’, ‘1’]
[‘a’, ‘e’, ‘1’]
[‘a’, ‘d’, ‘2’]
[‘a’, ‘e’, ‘2’]
[‘b’, ‘d’, ‘1’]
[‘b’, ‘e’, ‘1’]
[‘b’, ‘d’, ‘2’]
[‘b’, ‘e’, ‘2’]
[‘c’, ‘d’, ‘1’]
[‘c’, ‘e’, ‘1’]
[‘c’, ‘d’, ‘2’]
[‘c’, ‘e’, ‘2’]

Thx.

Here it is:
testing.dyn (80.9 KB)

Do you want them all, or does it make sense to test one by one? Also do combinations like [D, A, 1] want to be excluded?

You are correct. As you concluded, I don’t need different orders of an established combinations, meaning that I want [A, D, 1], but not [A,1,D], [D,1,A], [D,A,1], [1,D,A] and [1,A,D].

1 Like

I forgot that the previous uploaded dyn file required data from an excel file. It probably didn’t run on your computers.
Here is a new dyn file without the excel nodes:
testing2.dyn (82.1 KB)

Thx!

1 Like

Itertools returns a custom object as a class to reduce the memory consumption when used elsewhere in Python. Wrap it in a List(*) where * is the entire itertools function. Note this will return all iterations not just one, so you may need a get item at index method if you only want one option.

You may have a few longevity/stability issues to address as well - my attempt to run your graph produced a few errors in the python.

1 Like