Comparing two Lists and returning the distinct values and the differences
var A = new List<string>() { "A", "B", "C", "D" };
var B = new List<string>() { "A", "E", "F", "G" };
A.Except(B).ToList()
// outputs List<string>(2) { "B", "C", "D" }
B.Except(A).ToList()
// outputs List<string>(2) { "E", "F", "G" }
B.Intersect(A).ToList()
// outputs List<string>(2) { "A" }
Compare two list and get unique elements from first list Python
result = [i for i in A if i not in B]
Is there any way to find unique values between two lists without using a loop in dart
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.
Python Compare two lists and check for two unique strings
First you can find number of matches using list comprehension
and then len > 2
or not
>>> num = 2
>>> l = [i for i in strings if i in file]
>>> if len(l) >= num:
print('found')
found
unique values between 2 lists
After all the hassle with closing and re-opening I feel someone ought to actually answer the question.
There are different ways to achieve the desired result:
List comprehensions:
[i for i in f if i not in x]
. Maybe less efficient but preserves order. Credit goes to Chris_Rands (comment above).Set operations:
set(f) - set(x)
. Likely more efficient for larger lists but does not preserve order. Gredit goes to mpf82. This also removes duplicates inf
, as pointed out by asongtoruin.
Related Topics
Typeerror: Strptime() Argument 1 Must Be Str, Not List
Python Pip Install Error [Ssl: Certificate_Verify_Failed]
How to Correct Typeerror: Unicode-Objects Must Be Encoded Before Hashing
Python Super :Typeerror: _Init_() Takes 2 Positional Arguments But 3 Were Given
Key Error: None of [Int64Index...] Dtype='Int64] Are in the Columns
How to Check If a String Contains 2 of the Same Character
How to Get Elasticsearch to Perform an Exact Match Query
How to Split by Commas That Are Not Within Parentheses
How to Make Multiple Empty Lists in Python
Unable Log in to the Django Admin Page With a Valid Username and Password
Webscraping Financial Data from Morningstar
Pyqt: Getting Widgets to Resize Automatically in a Qdialog
How to Set Proxy Authentication (User & Password) Using Python + Selenium
Print a List of Space-Separated Elements