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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.