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 | Remove all values from a list present in other list
- Sum of all Palindrome Numbers present in a Linked list
- Python - Test rear digit match in all list elements
- Python - Test if all elements in list are of same type
- Python - Test for all Even elements in the List for the given Range
- Python | Add only numeric values present in a list
- Python - Find dictionary keys present in a Strings List
- Python program to find Maximum value from dictionary whose key is present in the list
- Python - Extract Key's Value, if Key Present in List and Dictionary
- Python - Check if any list element is present in Tuple
- Python - Remove dictionary from a list of dictionaries if a particular value is not present
- Python | OCR on All the Images present in a Folder Simultaneously
- Pandas - Get the elements of series that are not present in other series
- Python - Test if List contains elements in Range
- Python | Check if a Substring is Present in a Given String
- Python | Check if substring present in string
- Python | Check if element is present in tuple of tuples
- Python | Remove sublists that are present in another sublist
- Python | Check if element is present in tuple
- How to obtain the line number in which given word is present using Python?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.