两个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,' ...
随机推荐
- QFtp类参考
QFtp是一个用来实现FTP协议的类. 详情请见…… #include <qftp.h> 继承了QNetworkProtocol. 所有成员函数的列表. 公有成员 QFtp () virt ...
- VBoxGuestAdditions下载地址
http://dlc.sun.com.edgesuite.net/virtualbox/
- Object-c中的属性和成员变量的关系详解
很多人在初学移动开发的时候会对object-c中的合成存取方法感到疑惑,此处尝试为看到本文有缘人答疑解惑,鄙人才疏学浅,难免有疏漏谬误之处,热烈欢迎诸位看官拍砖指点. 1.合成存取方法: OC为增加开 ...
- Ubuntu 下安装VNC server
尽管我们在大部分情况下用ssh登录Ubuntu服务器就好了,但是有时候我们的程序需要在图形界面下运行,这时我们就要用到vnc server这个软件了.在Ubuntu下安装vnc server很简单的, ...
- HDU 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- [改善Java代码]使用静态内部类提高封装性
建议38: 使用静态内部类提高封装性 Java中的嵌套类(Nested Class)分为两种:静态内部类(也叫静态嵌套类,Static Nested Class)和内部类(Inner Class).内 ...
- CSS/块级元素与内联元素的深入理解
今天终于对html中的块级元素和行内元素有了一个较为理性的认识.首先w3c对于block和inline的解释为:
- jQuery API 3.1.0 速查表-打印版
jQuery API 3.1.0 速查表-打印图,(API来自:http://jquery.cuishifeng.cn/index.html)
- 在win下面使用cdt+cygwin+cmake
在cygwin终端下面, cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug 当收获警告 Could ...
- oracle储存过程,job,视图,触发器(记性不好,写个例子自己记)
存储过程 create or replace procedure TestPro(Descerr out varchar2 ) is begin select * from test; excepti ...