Compare two lists and create a unique resulting list

Hello,

I am trying to take List1, and compare it to List2, and have List3 give me the unique results.

All elements from List1, will always be in List2. It is the unique items in List2, that I need a list of.

Example:

List1: apples, pears, grapes
List2: apples, pears, grapes, watermelon, beer . (you always need :beer: )

List3 needs to be watermelon, beer

The problem I am having is creating a unique List. I am looping through and seeing if they match, but I am struggling removing duplicates.

Any pointers?

With AppyBuilder ListUtils extension you can remove duplicates easily:

Tried it however it retains one copy of all the duplicates.

I need an If duplicate - remove both copies.

My resulting list is a single unique representation of every tag., Make sense?

Wait… that’s not what you want
We have three lists: a (the longer list), b (the smaller list) and c (now empty, result will be here).
For each list item in a:
If not ((is list item? of list b [get item])) then {add item to list c
}

Thats a good way to put it.

However I do not knwo how to remove from a list without the index number.

the “is itme in list” is what I am trying to recreate

There is a block ‘index in list thing’

1 Like

PS:Look at the edited post, it doesn’t require that

nice task!
this seems to work :wink:

Edit:
ok in this case it works so far

if the order of his list is different, the result will not be (watermelon, beer)
exemple:
List2: beer, watermelon, grapes, pears, apples
result: pears,apples

, so it does not work !?

Ok so I solved this. I actually went one step further and made it full duplex, so that if there is something in list2 not in list1 it will e identified.

I tried a few different ways, but this was the only way it would actually work. I have created two lists and the result I am looking for is (watermelon beer cheery). Watermelon and beer is unique in list2 and cherry is unique in list1. Lets see how I got it.

Step 1

You have List1, List2, and an Empty Resulting list. Create two other empty lists, which we will use as the actual lists to manipulate.

Step 2

Create a function to do the analysis. and copy the two current lists to their temporary lists.

image

Step 3

Create a for loop. We are going to step through list1a items and see if they are in list2. But we are going to analyse list2b so we can manipulate it.

image

Step 4

Lets setup a local value for the index number. Then each item in list1 is looked up in List2b. If it exists it sends a True. Based on the true, we then get the index value from that item found in the list. Once we have the number, we then remove that index number from the list.

Step 5

Append the result to your final assembled resulting list

image

Step 6

Rinse and repeat. We Use List1a to compare against 2b. We use List2a to compare against 1b.

The result here is as we expect.

image

2 Likes

You forgot to cheers

I finally got it too :wink:

But now you have to make it full duplex so that anything on List2 not on list1 is also added :slight_smile:

:smiley: cool, a code battle!


erm,…41 Blocks. :wink:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Continuing the discussion from Compare two lists and create a unique resulting list:

I tried the above blocks for lists of NUMBERS but they dont seem work and remove single digit numbers if a double digit number with that digit is present in it. For example 2 will be removed if 12 is present in the other list.

See if this helps . If you wish to sort combined number list follow @WatermelonIce 's example as I did

1 Like

I am getting the error I mentioned for the same blocks.