Does python list contain all elements of another list?

不言
Release: 2018-05-05 10:22:44
Original
4240 people have browsed it

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的所有元素"
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!