对比list的处理速度

2014-10-31 0 523
对比list的处理速度
#网上代码
def open_httptxt():  #打开TXT文本写入数组
    st=time.clock()
    try:
        passlist = []
        list_passlist=[]
        xxx = file('http.txt', 'r')
        for xxx_line in xxx.readlines():
            #past.append(xxx_line)
            passlist.append(xxx_line)
        xxx.close()

        for i in passlist:  #python 列表去重
            if i not in list_passlist:
                list_passlist.append(i)

        E = 0 #得到list的第一个元素
        while E < len(list_passlist):
            #print list_passlist[E]
            past.append(list_passlist[E])  #添加到数组里
            E = E + 1
    except:
        return 0
    print 'open_http  ' +str(time.clock()-st)
#自己写的函数
def path_http():
    st=time.clock()
    
    f=open('http.txt','r')
    tlst=f.readlines()
    past = {}.fromkeys(tlst).keys() #去掉重复
    #past = list(set(tlst))
    print 'my def path_http  ' + str(time.clock()-st)
    f.close()
    return past

遇见资源网 python 对比list的处理速度 http://www.ox520.com/14845.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务