How to check if list contains all string of another list

python check if list contains elements of another list
python check if list contains all elements of another list
check if list is subset of another list python
python check if any element in list is in another list
python check if list contains another list
check if a list contains any elements of another list
check if any item in a list is in another list python
python check if all elements in list are in string

I have a object list. That object contains a string List. Like that:

public class ObjectA
{
    ...
    IList<string> StringList;
}

And I have a list of words to search on StringList. I need to search on a ObjectA list, and find all ObjectA that have all words (parts of all words).

So I did that:

 List<ObjectA> myObjectList;
 List<string> wordsToFind;  

 var result = myObjectList.Where(objectA => wordsToFind.All(objectA.StringList.Contains));

The problem is my result is getting only whole words (equals). I would like to get results that contains parts of my wordsToFind.

Example

wordsToFind = {"tes","don"};
StringListElement = {"test", "done"}

Should return on my select.

How can I do that?

Python : Check if a list contains all the elements of another list , In this article we will discuss if a list contains all or any elements of another list. Suppose we have have two list i.e.. # List of string. list1 = ['Hi'� A simple naive approach is to use two for loops and check if the whole list A is contained within list B or not. If such a position is met in list A, then break the loop and return true, otherwise false

The ways to do this is by using a combination of Any and All.

You need to check if all the elements of wordsToFind are substring of any elements in StringList

bool result = wordsToFind.All(word => currentObject.StringList.Any(str => str.Contains(word));

This is for one object out of the list of Objects. You can again apply All to that list.

Check if Python List Contains All Elements of Another List, There could be multiple ways to achieve it. all() method. To demonstrate that List1 has List2 elements, we'll use the all() method. any() method. Another method is any() which we can use to check if the list contains any elements of another one. Custom search. set() method. In this program, you will learn to check if the Python list contains all the items of another list and display the result using python print() function. We will use two lists, having overlapping values. One of these is the big one who holds all the items of the second one. List1 – The List1 contains all or some of the items of another list.

I think this should work for you

var wordsToFind = new List<string>{ "tes","don"};
var data= new List<ObjectA>()
{
    new ObjectA()
    {
        StringList = new List<string>{"test", "done", "blah"}
    },
    new ObjectA()
    {
        StringList = new List<string>{"test2", "done2", "blah2"}
    }
};

var result = (from item in data.Select(x => x.StringList)
              from bar in item
              from word in wordsToFind
              where bar.Contains(word)
              select bar)
              .ToList();

The result should give you

"test", "done","test2", "done2"

List containsAll() method in Java with Examples, The containsAll() method of List interface in Java is used to check if this List Creating another empty List. List<String> listTemp = new ArrayList<String>();. Python all () function checks if all Elements of given Iterable is True. So, convert the list2 to Iterable and for each element in Iterable i.e. list2 check if element exists in list1. Check if list1 contains any elements of list2 using any ()

Python, It contains well written, well thought and well explained computer science and Given two lists A and B, write a Python program to Check if list A is contained in If such a position is met in list A, then break the loop and return true, to join both lists to strings and then use in operator to check if list A is contained in B or not. The containsAll () method of List interface in Java is used to check if this List contains all of the elements in the specified Collection. So basically it is used to check if a List contains a set of elements or not.

Python Check if a list contains all the elements of another list , Python Check if a list contains all the elements of another list a. else if flag is False print means loop never breaks and all element list2 present in list1. 6. END Python Sorting a list of strings by Numerically in descending Order, 201, 14. In this sample program, you will learn to check if a Python list contains all the elements of another list and show the result using the print() function. To understand this demo program, you should have the basic Python programming knowledge. Check if Python List Contains Elements of Another List

List (Java Platform SE 8 ), Returns true if this list contains all of the elements of the specified collection. Returns a view of the portion of this list between the specified fromIndex, this method must allocate a new array even if this list is backed by an array). The following code can be used to dump the list into a newly allocated array of String: Solution 2 Your problem is that val is another List but Contains expects a string To see if one list contains the values in another use the List<t>.Intersect [ ^] method and check against the Count Any property

Comments
  • list a contain all word in list b? how about order? is it 100% match or?
  • Order is irrelevant
  • It would be awesome if you could provide a minimal reproducible example. Be sure to provide sample inputs and expected results based on those sample inputs.
  • Do you want ordinal comparison? stackoverflow.com/a/498722/34092
  • Thanks, Perfomance will not be a problem I guess, the lists are small. I liked your suggestion, but it is always returning empty result, idk why
  • @Paul added online demo
  • Thanks for details... I explained my needs wrong I think. All words from my search must be in my list, but I can have words on my StringList that are not on my search. I modified your sample, that should return both objects: dotnetfiddle.net/QqshRh
  • I modified your code and its working fine now! dotnetfiddle.net/z7Q3eW Thanks
  • @Paul thanks I was asleep heh, I'll fix the answer for future readers