List combination, Cartesian

Hello All,

I can not find the right nodes for what I would like to do.

Let’s assume I have 2 different lists, each of them contains 3 parameters. I would like to combine them as below:

This is going to largely depend on your datatypes. Laymens answers assuming you really are dealing with stings is to concatenate using cross product lacing (each item of listA gets matched with all items of listB):

Example using lines:

1 Like

Another option

2 Likes

2 Likes

Thanks @Thomas_Mahon & @Alisder_Brown & @Kulkul

How will it be if I would have more lists; like 4? The result should show 81

I just followed the code block that @Kulkul wrote. But I am sure I did not do it correctly

What is the output would you want with 4 lists?

@Alisder_Brown

3 * 3 * 3* 3 = 81

full combination of each list with others

As above?

2 Likes

@Raha_R Following the logic of your initial post, your math is incorrect since you don’t combine the first list with itself, meaning it should be 3 x 3 + 3 x 3 + 3 x 3:

listA;
otherLists;

t = [Imperative]
{
	concatList = {};
	for (i in GetKeys(listA)) //iterate through the input list
	{
		concatList[i] = {};
		for (j in GetKeys(otherLists) ) //Iterate through matching lists
		{
			for (a in GetKeys(otherLists[j]) )//Iterate through the members of the other lists
			{
				concatList[i] = List.AddItemToEnd(listA[i] + otherLists[j][a], concatList[i]);
			}
		}
	}
	return = concatList;
};
3 Likes

@Alisder_Brown Thanks so much! I think it’s exactly what I want.

@Thomas_Mahon you are right, in the case I really want to do full combination… but in my case, the “af” and “fa” doesn’t make difference because I will replace the strings with numbers that defined as the dimension of object…

1 Like

@Thomas_Mahon solution at its best :+1:. The imperative block.

2 Likes

2 Likes

Thank you all.

Now my question may seem stupid but I wonder how to do the same combination when the list contains numbers…
the + math may not work in this case? because it adds up the list numbers before combining

1 Like

Convert them to strings then back to numbers again if that’s important.

1 Like

@Thomas_Mahon Thank you. Yes it’s important because I want to feed them as parameter’s value.

how can I create a bunch of numbers as a list in each row? for example having list of numbers in each row…

1 Like

I also tried to separate them first and then combine, but again I don’t know the problem why they are not combined correctly.
Is there anyway to increase lacing or something like that?

1 Like

You’re kind of contradicting yourself with those images. Can you be clearer? Maybe just type precisely what you expect to see and what list structure you expect to see.

@Thomas_Mahon Sure. I hope these explanations make it clearer what I am looking for:

I have 4 different parametric objects (like the cylinder, cube, etc). one parameter from each one is desired to be changed. For example; I want to change the height of each one.
I also defined 4 different lists (for each parameter), which contain 3 numbers as the ranges that are supposed to be fed into parameters value.

What I am going to do is automatically generate the changes while covering the possible combinations from the first list to the other lists (I don’t need to combine the first list with itself). the results I am expecting is
3x3x3x3.
I want to feed these combined values into the loop and change all of the heights simultaneously (so as a result; I will see objects with different heights in each loop.)

“Now my problem is to combine the lists like how I need, then use it as parameter value…”

I hope my detailed explanation doesn’t bring up more ambiguity.

1 Like

@Raha_R If I’ve understood your intent, what you need is very straightforward

2 Likes