Home >Backend Development >Python Tutorial >Does python list contain all elements of another list?
This article mainly introduces whether a python list contains all elements of another list. It has a certain reference value. Now I share it with you. Friends in need can refer to it
As shown below:
#!/usr/bin/env python # coding: utf-8 a = [1, 2, 3, 4, 5] b = [3, 4, 5] d = [False for c in b if c not in a] if d: print "a不包含b的所有元素" else: print "a包含b的所有元素"
You can also consider converting to a set and then finding the intersection to see if it is equal to the smaller set.
Related recommendations:
Python implementation example of finding all subsets of a set
Python determines whether a set is another set Subset method of a collection
The above is the detailed content of Does python list contain all elements of another list?. For more information, please follow other related articles on the PHP Chinese website!