python中,遍历dict的方法有四种。但这四种遍历的性能如何呢?我做了如下的测试
l = [(x,x) for x in xrange(10000)]
d = dict(l)
from time import clock
t0=clock()
for i in d:
t = i + d[i]
t1=clock()
for k,v in d.items():
t = k + v
t2=clock()
for k,v in d.iteritems():
t = k + v
t3=clock()
for k,v in zip(d.iterkeys(),d.itervalues()):
1