Sometimes, while working with Python list, we have a problem in which we need to check for a particular list of values and want to be sure if a target list contains all the given values. This has it’s application in web development domain when required some type of filtering. Let’s discuss a way in which this task can be performed.
Method : Using list comprehension +
This task can be performed using the inbuilt functionality of all(). The all() can be fed with list comprehension logic to check if element of test list is present in target list and rest is done by
The target list : [6, 4, 8, 9, 10] The test list : [4, 6, 9] Does every element of test_list is in target_list ? : True
- Python - Test rear digit match in all list elements
- Python | Remove all values from a list present in other list
- Python | Add only numeric values present in a list
- Python | Subtract two list elements if element in first list is greater
- Python | Sorting list of lists with similar list elements
- Python | Add list elements with a multi-list based on index
- Python | Merge List with common elements in a List of Lists
- Python | Replace elements in second list with index of same element in first list
- Python | Indices of sorted list of list elements
- Python | Maximum sum of elements of list in a list of lists
- Python | Test for nested list
- Python | Test for False list
- Python | Test list element similarity
- Python - Test for strictly decreasing list
- Python | Test if string contains element from list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.