Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to find unique values between two lists without using a loop in dart

Tags:

flutter

dart

Is there any way to find unique values between two lists without using a loop?

List<String> first = ['A','B','C','D']; 
List<String> second = ['B','D']; 

I need the result to be like this:

result = ['A','C'];
like image 598
BIS Tech Avatar asked Dec 29 '19 04:12

BIS Tech


People also ask

How do you compare two List values in flutter?

here == operator the instance of the list not the content, where are equals method compare the data inside lists. List<String>list3=list1; print(list1==list3);

How to quickly select the unique or distinct list in Excel?

To quickly select the unique or distinct list including column headers, filter unique values, click on any cell in the unique list, and then press Ctrl + A. To select distinct or unique values without column headers, filter unique values, select the first cell with data,...

How do you find the unique values in a list?

Find unique values in a column To find distinct or unique values in a list, use one of the following formulas, where A2 is the first and A10 is the last cell with data. How to find unique values in Excel: =IF (COUNTIF ($A$2:$A$10, $A2)=1, "Unique", "")

How do you find the distinct rows in an array?

Formula to find distinct rows: If you are working with a data set where case matters, you'd need a bit more trickier array formula. Finding case-sensitive unique values: Finding case-sensitive distinct values: Since both are array formulas, be sure to press Ctrl + Shift + Enter to complete them correctly.

What is the difference between unique and distinct values?

Unique values are the items that appear in a dataset only once. Distinct values are all different items in a list, i.e. unique values and 1 st occurrences of duplicate values. And now, let's investigate the most efficient techniques to deal with unique and distinct values in your Excel sheets.


1 Answers

You can use where() with contains() methods from List:

void main() {
  List<String> first = ['A','B','C','D']; 
  List<String> second = ['B','D'];

  List<String> result = first.where((item) => !second.contains(item)).toList();
  print(result); // [A, C]
}

Edit in DartPad.

like image 147
Blasanka Avatar answered Oct 19 '22 16:10

Blasanka