两个list 求交集效率对比
__author__ = 'daitr'
#--coding:utf-8--
import datetime
#方法一:
#a=[2,3,4,5]
#b=[2,5,8]
#tmp = [val for val in a if val in b]
#print tmp
##[2, 5] #方法二
#print list(set(a).intersection(set(b)))
#print list(set(a).union(set(b)))
#print list(set(b).difference(set(a))) # b中有而a中没有的 a,b= [],[]
for i in range(1,60000):
a.append(i) for j in range(40000,100000):
b.append(j)
print a[-1]
print b[-1] time1 = datetime.datetime.now()
#print time1 tmp = [val for val in a if val in b]
#print tmp time2 = datetime.datetime.now()
#print time2
d1 = time2-time1
print d1 list(set(a).intersection(set(b)))
#print temp2 time3 = datetime.datetime.now()
#print time3
d2 = time3-time2
print d2

两个list 求交集效率对比的更多相关文章
- python中对两个 list 求交集,并集和差集
python中对两个 list 求交集,并集和差集: 1.首先是较为浅白的做法: >>> a=[1,2,3,4,5,6,7,8,9,10] >>> b=[1,2,3 ...
- python 两个list 求交集,并集,差集
def diff(listA,listB): #求交集的两种方式 retA = [i for i in listA if i in listB] retB = list(set(listA).inte ...
- Linux 两个文件求交集、并集、差集
一.交集 sort a.txt b.txt | uniq -d 二.并集 sort a.txt b.txt | uniq 三.差集 a.txt-b.txt: sort a.txt b.txt b.tx ...
- list1与list2求交集的方法总结!
一.有序集合求交集的方法有 a)二重for循环法,时间复杂度O(n*n) b)拉链法,时间复杂度O(n) c)水平分桶,多线程并行 d)bitmap,大大提高运算并行度,时间复杂度O(n) e)跳表, ...
- SIMD---SSE系列及效率对比
SSE(即Streaming SIMD Extension),是对由MMX指令集引进的SIMD模型的扩展.我们知道MMX有两个明显的缺点: 只能操作整数. 不能与浮点数同时运行(MMX使用FPU寄存器 ...
- 【C++】Vector判断元素是否存在,去重,求交集,求并集
1 #include <iostream> 2 #include <vector> 3 #include <algorithm> //sort函数.交并补函数 4 ...
- [c++]对vector<T>容器求交集,并集,去重
#include "iostream" #include "vector" #include "algorithm" //sort函数.交并 ...
- 求两个集合的交集和并集C#
我是用hashset<T>来实现的 具体如代码所示 using System; using System.Collections.Generic; using System.Linq; u ...
- SQLServer中求两个字符串的交集(字符串以符号分隔)
两个字符串,以特定符号分隔(例如‘,’号),求交集 第一种情况: declare @m varchar(100),@n varchar(100)select @m=',2,3,5,7,8,9,10,' ...
随机推荐
- Qt Quick实现的疯狂算数游戏
使用 Qt Quick 写了个小游戏:疯狂算数.支持 Windows 和 Android 两个平台. 游戏简单,但牵涉到下面你的 Qt Quick 主题: 自己实现一个按钮 自适应分辨率 国际化 QM ...
- css笔记03:伪类first-child
1. 匹配第一个 <p> 元素 在下面的例子中,选择器匹配作为任何元素的第一个子元素的 p 元素: <html> <head> <style type=&qu ...
- 前端必会css整理
1.设置css样式的三种方式? 外部样式表,引入一个外部css文件 内部样式表,将css代码放在<head>标签内部 内联样式,将css样式 ...
- SSIS 学习(6):包配置(上)【转】
Integrartion Services 包实际上就是一个对象属性的集合,在前面我们开发的所有 Integration Services包,其中的变量.属性,比如:数据库链接.同步文件目录等,我们都 ...
- [改善Java代码]异步运算考虑使用Callable接口
多线程有两种实现方式: 一种是实现Runnable接口,另一种是继承Thread类,这两种方式都有缺点,run方法没有返回值,不能抛出异常(这两个缺点归根到底是Runable接口的缺陷,Thread也 ...
- hdu 4630 树状数组
思路:这题的处理方式和hdu4358有点像.我们用一个pre[x]表示约数x的倍数上次出现的位置,将查询按区间的右节点升序排序.num[i]的约数为j,如果pre[j]为0,就将pre[j]置为i;否 ...
- HTML-块级元素和内联元素
HTML-块级元素和内联元素 块级元素 内联元素 address - 地址 block - 块引用 center - 居中对齐块(不推荐) dir - 目录列表(HTML5踢出) div - 常用的不 ...
- MyBatis(3.2.3) - Custom ResultSet processing using ResultSetHandler
MyBatis provides great support with plenty of options for mapping the query results to JavaBeans. Bu ...
- 个人常用jq方法复习
$("#elem").on({ mouseover:function(){}, mouseout:function(){}, }); $(ele).closest("di ...
- C#程序员整理的Unity 3D笔记(十三):Unity 3D基于组件的思想
如果你接触过<设计模式>.软件架构的编程思想,就会知道优秀的设计准则:“组合优于继承的”. 这句话很简短,但开始学习OOP的时候,真切的是—-不太好理解(以我个人当初学习为例). OOP的 ...