Compare two lists and create a unique resulting list

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.

Post your blocks please

I used these blocks

now I’ve changed my blocks

Does it work now that you changed them ?

My app is crashing due to some other reason. I am working to solve that first. (I guess its related to using two firebase realtime database url in the same app. I’m not sure if its possible, but my app worked initially but now unable to fetch data from the second project.)
#beginner

Solved!

Add two list into a third list, remove duplicates.

Then use this block to remove items from the longer list of the two

Ta-da!