Using LINQ I have a list of lists, how do I select all objects that exist in every list?

NibblyPig

I have a list of lists:

List<Tuple<string, List<SomeObject>>

I want to select all SomeObjects that exist in all rows of the list above.

Some will just exist in one or two lists, but I want all objects that exist in every single list, with other objects discarded.

I can't figure out an elegant solution to this without a bunch of c# code. Is there a nice way?

Juan Lopes
list.Select (x => x.Item2 as IEnumerable<SomeObject>)
    .Aggregate((x,y)=> x.Intersect(y))
    .ToList();

Or, as Jeppe Stig Nielsen suggested (and I think it's much more elegant):

list.Select(x => x.Item2.AsEnumerable())
    .Aggregate(Enumerable.Intersect)
    .ToList();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I group a list using Linq

From Dev

How do I select lists inside a list that have a specific length in Haskell?

From Dev

I have two lists containing the same objects. How do I change one list without changing the other?

From Dev

How can I retrieve all Objects in a List that have certain attributes?

From Dev

How do I delete all the sub-lists from a list?

From Dev

How do I delete all the sub-lists from a list?

From Dev

How do I apply OrderBy to a Linq Query for a select list

From Dev

how do I concatenate 3 lists using a list comprehension?

From Dev

How do I list all instantiated objects in Python?

From Dev

How do I select list of generic objects in abstract service using CriteriaQuery

From Dev

Maya, PYTHON: how do i select all but one in a list?

From Dev

Can I use LINQ to check if objects in a list have a unique ID?

From Dev

In Git, how can I list all files that exist in branch A that do not exist in branch B

From Dev

How do I handle a List of Lists?

From Dev

How do I insertion sort a list of lists?

From Dev

Using LINQ. With two different lists. How can I identify objects that do not match

From Dev

I want to make a regular select list with AngularJs have a preselected option, how do I do that?

From Dev

I'm getting a list of lists that each have one tuple. How do I get one list with several tuples?

From Dev

I have created a horizontal List view. Now I want this horizontal listview in every item of Vertical List View .How to do this??

From Dev

How to select all objects that have a property value in list of values?

From Java

How do I get list of all tables in a database using TSQL?

From Dev

How do I get all the selected list Items using Checkbox

From Dev

How do I uncheck the other selected list items that was previously select after I click on "Select All"?

From Dev

How can I tell if I have a list of File objects?

From Dev

OCaml - How do I return list of lists from a list?

From Dev

In R, how do I restrict a list of lists based on another list?

From Dev

How do I fetch a list of objects in grails?

From Dev

How do I convert a Python list of lists of lists into a C array by using ctypes?

From Dev

c# and Lists: How do I use the foreach loop to retrieve the objects form my list?

Related Related

  1. 1

    How do I group a list using Linq

  2. 2

    How do I select lists inside a list that have a specific length in Haskell?

  3. 3

    I have two lists containing the same objects. How do I change one list without changing the other?

  4. 4

    How can I retrieve all Objects in a List that have certain attributes?

  5. 5

    How do I delete all the sub-lists from a list?

  6. 6

    How do I delete all the sub-lists from a list?

  7. 7

    How do I apply OrderBy to a Linq Query for a select list

  8. 8

    how do I concatenate 3 lists using a list comprehension?

  9. 9

    How do I list all instantiated objects in Python?

  10. 10

    How do I select list of generic objects in abstract service using CriteriaQuery

  11. 11

    Maya, PYTHON: how do i select all but one in a list?

  12. 12

    Can I use LINQ to check if objects in a list have a unique ID?

  13. 13

    In Git, how can I list all files that exist in branch A that do not exist in branch B

  14. 14

    How do I handle a List of Lists?

  15. 15

    How do I insertion sort a list of lists?

  16. 16

    Using LINQ. With two different lists. How can I identify objects that do not match

  17. 17

    I want to make a regular select list with AngularJs have a preselected option, how do I do that?

  18. 18

    I'm getting a list of lists that each have one tuple. How do I get one list with several tuples?

  19. 19

    I have created a horizontal List view. Now I want this horizontal listview in every item of Vertical List View .How to do this??

  20. 20

    How to select all objects that have a property value in list of values?

  21. 21

    How do I get list of all tables in a database using TSQL?

  22. 22

    How do I get all the selected list Items using Checkbox

  23. 23

    How do I uncheck the other selected list items that was previously select after I click on "Select All"?

  24. 24

    How can I tell if I have a list of File objects?

  25. 25

    OCaml - How do I return list of lists from a list?

  26. 26

    In R, how do I restrict a list of lists based on another list?

  27. 27

    How do I fetch a list of objects in grails?

  28. 28

    How do I convert a Python list of lists of lists into a C array by using ctypes?

  29. 29

    c# and Lists: How do I use the foreach loop to retrieve the objects form my list?

HotTag

Archive