Compare each element of listA with all elements of listB: DesignScript and Python

Hey guys,

I want to compare each element of one list to all elements of a second list.
In Python I could write:

for i in listA
if i in listB:
"do this"
else:
“do this”

is there and equivalent in DesignScript for “if i in listB”?

Any help is much appreciated.:grinning:

Thank you.

Looking for something like this?

for loops are also possible in Imperative code blocks.

2 Likes

as Vikram said :

5 Likes

Similar to what @Mostafa_El_Ayoubi has shown, but without defining a function …

x = [Imperative]
{
a = 1..3;
b = {2,2,3,1};

c = 0;
z = {};

for (i in a)
	{
	d = 0;
	for (j in b)
		{
		if (j == i)
			{
			z[c][d] = "ABCD";
			d = d+1;
			}
		else
			{
			z[c][d] = "wxyz";
			d = d+1;
			}
		}
	c = c+1;
	}
return = z;
};
1 Like

@ Mostafa. That’s what I was looking for :smiley:. Thanks a lot :smiley::smiley: