Python中list查询及所需时间计算操作示例-创新互联
本文实例讲述了Python中list查询及所需时间计算操作。分享给大家供大家参考,具体如下:

# -*-coding=utf-8 -*-
#! python2
#filename: list_query
#date: 2018-03-25
#author: guosw
import time
def cost_time(fun):
def cost(*args,**kwargs):
stime = time.time()
x = fun(*args,**kwargs)
etime = time.time()
print "function name:",fun.__name__
print "time cost:",etime-stime
return x
return cost
@cost_time
def list_query(_list,_val):
low = 0
height = len(i) - 1
mid = (height - low) // 2
for n in xrange(height+1):
if _list[n] == _val:
return n
for n in xrange(mid,height+1):
if _list[n] == _val:
return n
if __name__ == "__main__":
i = xrange(100000)
subscript = list_query(i,9999)
print subscript
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
名称栏目:Python中list查询及所需时间计算操作示例-创新互联
本文链接:http://www.jxjierui.cn/article/cooeeg.html


咨询
建站咨询
