Home  >  Article  >  Backend Development  >  Does python list contain all elements of another list?

Does python list contain all elements of another list?

不言
不言Original
2018-05-05 10:22:444291browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn