Checking if list A is in list B

To chek if list A is completely included in list B – all elements of list A are present in list B, we can use the “superset” and “subset” methods of the standard Python “set” class.

Converting lists to sets also allows us not to worry about checking for duplicates if they exist in the compared lists.


The “subset” method acts on a smaller set and checks if it is in a larger set.


The “superset” method, on the contrary, checks the larger set to see if it contains a smaller set.

We can also use the “<=” operator to check our lists:


0 0 votes
Article Rating
Notify of
0 Комментарий
Inline Feedbacks
View all comments