JSON

pyuthon高级技巧2

字号+ 作者:H5之家 来源:H5之家 2017-01-24 13:05 我要评论( )

listordict在需要重复查找的时候,dicty用hash表示实现,复杂度为O(1),list的复杂度为O(n)data_list=[

list or dict
在需要重复查找的时候,dicty用hash表示实现,复杂度为O(1),list的复杂度为O(n) data_list=['a','b','is','python','jason','hello','hill','with','phone','test', 'dfdf','apple','pddf','ind','basic','none','baecr','var','bana','dd','wrd'] data_dict=dict.fromkeys(mlist,True) print(data_dict) {'b': True, 'pddf': True, 'baecr': True, 'ind': True, 'var': True, 'python': True, 'a': True, 'none': True, 'with': True, 'bana': True, 'hill': True, 'is': True, 'wrd': True, 'apple': True, 'dfdf': True, 'dd': True, 'test': True, 'phone': True, 'basic': True, 'hello': True, 'jason': True}

下面对两种进行计时

def gettime(mylist): t=time() #list = dict.fromkeys(list,True) mfilter = [] for i in range (10000): for wd in ['is','hat','new','list','old','.']: if wd not in mylist: mfilter.append(wd) print("total run time:",time()-t) gettime(data_list) total run time: 0.21671438217163086 gettime(dict_list) total run time: 0.044046878814697266

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 基于json的AJAX高级开发技术

    基于json的AJAX高级开发技术

    2017-01-22 12:02

  • JSON学习之完全手册图文

    JSON学习之完全手册图文

    2017-01-12 18:01

  • 新人发帖:求关于重新修改密码的技巧

    新人发帖:求关于重新修改密码的技巧

    2017-01-10 17:01

  • ASP.NET中DataGrid控件应用技巧简述

    ASP.NET中DataGrid控件应用技巧简述

    2017-01-10 17:00

网友点评