# Compare two unequal lists

I’m trying to compare 2 lists with equal numbers in each list but similar values.

e.g. 1,2,3,5,7,8,9 and 1,2,3,4,5,6,7,8,9. The result i’m looking for is

true
true
true
false
true
false
true
true
true

Could someone point me in the right direction of where to start, I’ve tried comparing lists with a formula node but that only works until the lists get out of sync and beyond that I’m at a loss…

Try this:

As you want the result from the longest list, ensure the lacing method for the List.ContainsItem node is set to Longest

EDIT: Realised this only works if your indexes match! Swap the inputs of the List.ContainsItem, no need to do Longest lacing:

3 Likes

Slick, thanks for that, I’ve added that to my library of useful functions!

I have one other question though - if you look at the attached script, is there an easy way to apply the boolean function to sublists rather than the top level list? Please forgive me if this is obvious but just now I need to run the filter on each list individually once I’ve separated them out.

The purpose of the script is to update room data.

Thanks for looking at this - for now I’m running with Thomas’ solution as it’s just using standard nodes rather than code (my understanding of code is improving but still has a long way to go!).

Hope this gets you to reconsider the use of code …

7 Likes

Hi @Keith_Wilkinson1 yes, add a List.Map into the mix:

Make sure List.ContainsItem is set to Longest lacing

1 Like

haha, that’s very slick indeed…

Seems like while using List.ContainsItem things can be managed with changes to Lacing

Another option could be to use a python node, the code’s pretty simple

4 Likes

I am trying to compare these lists but by using the methods mentioned above, but I does not work. Any ideas? I have tried to set the nod to longest and to shortest in the List.ContainsItem node but it still does not work.

Is your main list made up of strings or numbers? Try running it through a String To Number node and see what you get back.

I think it is numbers. I get errors when I try string to numbers…

I’ll be honest I can’t see any other reason it doesn’t work but maybe someone else can…

As another option you could try converting your numbers in your codeblock to strings just to see if you get a result.

Place an Object.Type node after each list and preview the results. If the object types don’t match then the objects can’t match.

Think of it like languages. “Uno” and “ett” and “one” all mean 1, but they aren’t the same.

1 Like

@Vikram_Subbaiah, really simple and easy way to play with boolean values as a beginner. I tried to do as you, but I get a wrong output. Why is that? Any suggestions?

Use List.ContainsItem, not List.Contains

If its af build in node, it seems like List.ContainsItem is not to find within the latest Dynamo version.

Use list levels.

1 Like

It’s a core node and is there in 1.3.3 - not looked at 2.0.