转载自:http://blog.csdn.net/wzgbm/article/details/54691615 首先给一个简单的例子,测测list和dict查找的时间: ,-,-,-,-,,,,,,] lst = [] dic = {} ): lst.append(i) dic[i] = start = time.time() for v in query_lst: if v in lst: continue end1 = time.time() for v in query_lst: if v…
函数之间传递list: def show(ll): for i in ll: print(i) show(['chen','hang','wang','yadan']) #========================================== chen hang wang yadan *args:输入数据长度不确定,通过*args将任意长度的参数传递给函数,系统自动将任意长度参数用list表示 def show(*args): for i in args: print(i) sho…
import pickle, json, csv, os, shutil class PersistentDict(dict): ''' Persistent dictionary with an API compatible with shelve and anydbm. The dict is kept in memory, so the dictionary operations run as fast as a regular dictionary. Write to disk is d…
for循环体内的语句只有一行的情况的下,可以简化for循环的书写,尤其当你需要生成一个可迭代对象的时候 d = {x:x*10 for x in range(3)} print(d) d1 = [x*10 for x in range(3)] print(d1) 输出: {0: 0, 1: 10, 2: 20} [0, 10, 20] d=dict((k,'sss') for k in ('modelID', 'userIP')) print(d) 输出: {'userIP': 'sss', '…