Python 基础 - 随机列表的交集

时间:2023-03-09 16:33:03
Python 基础 - 随机列表的交集
# -*- coding: utf-8 -*-
#author:v
def shiyiwenpapa():
def sywmemeda(l): #冒泡排序
length = len(l)
for i in range(length-1,0,-1):
#print(i)
for j in range(i):
if l[j] > l[j+1]:
l[j],l[j+1] = l[j+1],l[j] def randomlist(): #生成随机数列
import random
list=[]
i=0
while i<7:
i+=1
list.append(random.randint(1,10))
return list
list1=randomlist()
#print(list1)
sywmemeda(list1)
syw=list(set(list1))
sywmemeda(syw)
return syw a=shiyiwenpapa()
b=shiyiwenpapa()
c=[]
for n in a:
if n in b:
c.append(n)
#c=list(a.intersection(b))
print " %s与%s的交集为:%s"%(a,b,c)