国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python中list查詢及所需時間計算操作示例

2020-02-15 21:56:47
字體:
來源:轉載
供稿:網友

本文實例講述了Python中list查詢及所需時間計算操作。分享給大家供大家參考,具體如下:

# -*-coding=utf-8 -*-#! python2#filename: list_query#date: 2018-03-25#author: guoswimport timedef 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_timedef 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 nif __name__ == "__main__":  i = xrange(100000)  subscript = list_query(i,9999)  print subscript

運行結果:

function name: list_query
time cost: 0.00100016593933
9999

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python數組操作技巧總結》、《Python字符串操作技巧匯總》、《Python函數使用技巧總結》、《Python入門與進階經典教程》及《Python數據結構與算法教程》

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长岛县| 淮北市| 潼南县| 宣恩县| 中牟县| 济南市| 乌拉特中旗| 长武县| 苏州市| 麻城市| 台湾省| 新津县| 临安市| 威远县| 潮安县| 桂平市| 襄樊市| 峡江县| 涞水县| 新乐市| 梓潼县| 镇原县| 平潭县| 云安县| 桓台县| 云阳县| 平昌县| 马山县| 简阳市| 镇平县| 三穗县| 大余县| 沿河| 信阳市| 三明市| 桂平市| 普格县| 屏山县| 安义县| 高密市| 成安县|