Two lists: {code...} are generated, and the Union is set. The concept of difference set is not mentioned here. the python code is as follows: {code...} generates two
List
:
A = ['apple','apple','banana']B = ['banana','apple','banana']
The concept of intersection and union is not mentioned here. the python code is as follows:
#! /usr/bin/env python# coding:utf-8listA = [1, 2, 3, 4, 5, 6]listB = [4, 5, 6, 7]# Intersectioninte = list(set(listA).intersection(set(listB)))print "Intersection:", inte# unionuni = list(set(listA).union(set(listB)))print "Union:", uni# Differencesdiff = list(set(listA).difference(set(listB)))print "Differences:", diff
if diff: print "wrong"else: print "matched"
TwoList
:
A = ['apple','apple','banana']B = ['banana','apple','banana']
The concept of intersection and union is not mentioned here. the python code is as follows:
#! /usr/bin/env python# coding:utf-8listA = [1, 2, 3, 4, 5, 6]listB = [4, 5, 6, 7]# Intersectioninte = list(set(listA).intersection(set(listB)))print "Intersection:", inte# unionuni = list(set(listA).union(set(listB)))print "Union:", uni# Differencesdiff = list(set(listA).difference(set(listB)))print "Differences:", diff
if diff: print "wrong"else: print "matched"
The above is the details of the Python List intersection, union, and difference set applications. For more information, see other related articles in the first PHP community!