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.

Check if list1 contains all elements of list2 using all()

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 any() function checks if any Element of given Iterable is True. So, convert the list2 to Iterable and for each element in Iterable i.e. list2 check if any element exists in list1.

Complete example is as follows,

Output:

 

Click Here to Subscribe for more Articles / Tutorials like this.