There are two lists:
List<string> excluded = new List<string>() { ".pdf", ".jpg" }; List<string> dataset = new List<string>() {"valid string", "invalid string.pdf", "invalid string2.jpg","valid string 2.xml" };
How can I filter-out values from the "dataset" list which contain any keyword from the "excluded" list?
The remove() method removes the first matching element (which is passed as an argument) from the list. The pop() method removes an element at a given index, and will also return the removed item. You can also use the del keyword in Python to remove an element or slice from a list.
In Python, use list methods clear() , pop() , and remove() to remove items (elements) from a list. It is also possible to delete items using del statement by specifying a position or range with an index or slice.
RemoveAt (Int32) Method is used to remove the element at the specified index of the List<T>. Properties of List: It is different from the arrays.
Exclude values in one list from another with formula. Quickly exclude values in one list from another with Kutools for Excel. Easily exclude values in one list from another in Excel: The Select Same & Different Cells utility of Kutools for Excel can help you quickly selecting all same cells in one list based on values in another column.
To get the items from list one list (A) that are not in another list (B) you can use the Linq Except method like this: var a = new List<int>() { 1, 2, 3, 4, 5 }; var b = new List<int>() { 2, 4, 9, 16, 25 }; var aNotB = a.Except(b); aNotB.ToList().ForEach(x => Console.WriteLine(x)); Which will produce the following results: 1 3 5
Select a blank cell which is adjacent to the first cell of the list you want to remove, then enter formula =COUNTIF ($D$2:$D$6,A2) into the Formula Bar, and then press the Enter key.
There are all sorts of reasons you might want the values from one list that aren’t in another, for instance: Say you have a shopping list, but you’ve just been to the store and bought some of the items, you might want to get everything on the original shopping list that you didn’t just purchase:
var results = dataset.Where(i => !excluded.Any(e => i.Contains(e)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With