list-comparison

How to compare two generic lists in C# 3.0? [duplicate]

早过忘川 提交于 2019-12-20 06:28:21
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Is there a built-in method to compare collections in C#? What is the best way to compare to generic two generic lists in C# 3.0? 回答1: If you want to compare regardless of element order, try the UnorderedEqual<T> method from here: C# List Element Equality Otherwise: var list1 = new List<int> { 1, 2, 3 }; var list2 = new List<int> { 1, 2, 3 }; var areSame = Enumerable.SequenceEqual(list1, list2); 回答2: Check out

Difference between two List<FileInfo>

旧城冷巷雨未停 提交于 2019-12-18 13:23:40
问题 Can I use a fancy LINQ query to return a List<FileInfo> , by passing it in a method ( List<FileInfo> oldList, List<FileInfo> newList ), and seeing what differences there are between the two lists? Basically, I want to get a list of any files added to newList, that were not available in oldList. 回答1: Given an IEqualityComparer for FileInfo shown below: public class FileInfoEqualityComparer : IEqualityComparer<FileInfo> { public bool Equals(FileInfo x, FileInfo y) { return x.FullName.Equals(y

Comparing two lists for unique items in each

ぃ、小莉子 提交于 2019-12-14 00:54:53
问题 I have two collections (they happen to be arrays, but it doesn't really matter, I think): L and R . They are both sorted and now I want to compare them. I want to end up with two collections: one for each input array containing the items which were not in the other. I could just take the first item from L and then search R and, if there isn't a match, add it to my "unique" collection ( Lu ). But that's extremely inefficient, and I am expecting to have some very large collections to process in

How to compare two txt files and then apply changes in one of them

折月煮酒 提交于 2019-12-11 19:08:18
问题 I am trying to merge two text (PDB) files. One (bigger one) contains full set of data describing the protein, second one contains very small set of data changing just small part (set of coordinates). Example: Basic file (part): ATOM 605 CD2 LEU A 92 11.727 14.051 55.011 1.00 75.51 4pxz C ATOM 606 N ARG A 93 10.555 10.636 58.260 1.00 62.79 4pxz N ATOM 607 CA ARG A 93 11.357 9.429 58.493 1.00 59.89 4pxz C ATOM 608 C ARG A 93 10.429 8.207 58.562 1.00 62.83 4pxz C ATOM 609 O ARG A 93 10.760 7.168

How to compare two generic lists in C# 3.0? [duplicate]

大兔子大兔子 提交于 2019-12-02 08:29:25
Possible Duplicate: Is there a built-in method to compare collections in C#? What is the best way to compare to generic two generic lists in C# 3.0? If you want to compare regardless of element order, try the UnorderedEqual<T> method from here: C# List Element Equality Otherwise: var list1 = new List<int> { 1, 2, 3 }; var list2 = new List<int> { 1, 2, 3 }; var areSame = Enumerable.SequenceEqual(list1, list2); Rohan West Check out this answer , it provides a method that determines whether two sequences contain the same elements. If you want to compare two sequences in .NET 3.5 and beyond (that

Testing if a list contains another list with Python

我的梦境 提交于 2019-11-26 14:41:54
How can I test if a list contains another list (ie. it's a contiguous subsequence). Say there was a function called contains: contains([1,2], [-1, 0, 1, 2]) # Returns [2, 3] (contains returns [start, end]) contains([1,3], [-1, 0, 1, 2]) # Returns False contains([1, 2], [[1, 2], 3]) # Returns False contains([[1, 2]], [[1, 2], 3]) # Returns [0, 0] Edit: contains([2, 1], [-1, 0, 1, 2]) # Returns False contains([-1, 1, 2], [-1, 0, 1, 2]) # Returns False contains([0, 1, 2], [-1, 0, 1, 2]) # Returns [1, 3] Here is my version: def contains(small, big): for i in xrange(len(big)-len(small)+1): for j in

Testing if a list contains another list with Python

强颜欢笑 提交于 2019-11-26 03:58:38
问题 How can I test if a list contains another list (ie. it\'s a contiguous subsequence). Say there was a function called contains: contains([1,2], [-1, 0, 1, 2]) # Returns [2, 3] (contains returns [start, end]) contains([1,3], [-1, 0, 1, 2]) # Returns False contains([1, 2], [[1, 2], 3]) # Returns False contains([[1, 2]], [[1, 2], 3]) # Returns [0, 0] Edit: contains([2, 1], [-1, 0, 1, 2]) # Returns False contains([-1, 1, 2], [-1, 0, 1, 2]) # Returns False contains([0, 1, 2], [-1, 0, 1, 2]) #