Compare two lists

Hi!

I have a list of strings: list1 = (“1”, “1”, “2”) and list2 = (“1”, “2”). Now I would like to get the value (“1”) as result, which is the value which is added to list1.

Thinking of counting the number of the unique elements and compare these values. Is there an easier solution?

Thank you in advance and kr,
GrKa

Hi,

One of the easiest way, remove items which exists List2 from List1 as the following.
If you keep values of List1, please copy it in advance.

note: ArgumentType of ForEach is String

if you have large list, it’s better to use Invoke Code activity.

Regards,

1 Like

Hi

Welcome back to uipath forum

Use a simple assign activity like this

Final_list = list1.Except(list2)

Where Final_list is a variable of type
System.Collections.Generic.List(of Int32)

Cheers @GrKa

4 Likes

Hi @Palaniyappan Can this be achieved where the lists are of type string?

Thank you

Yes,
grafik

But we do see, that it is deduplicating, Therefore we do get an empty list returned

An implementation keeping the duplicates and reducing by list occurence count could look like this:

But we also recommend to checkout the suggestion from @Yoichi given above

1 Like

Excellent! Thank you

Hi @GrKa

  1. Assign two List Variables say List1 and List2 of datatype System.Collections.Generic.List(String).
List1= New List(of String) from {"A","B","C","D"}
List2= New List(of String) from {"B","D"}
  1. Use For each loop to iterate through List1
  2. Use an Assign activity and write the below syntax
currentItem=Item.ToString
  1. Use an if activity and write the below condition
List2.Contains(Item)
  1. Use an assign activity and create an variable ItemExists of datatype Boolean.
  2. Use Log message to print the value.

Note: Attached workflow for your reference
Sequence7.xaml (10.1 KB)

Hope it helps!!
Regards,

Check out this thread for more information.

Regards,