What is the advantage of iteritems?

后端 未结 5 1088
独厮守ぢ
独厮守ぢ 2021-02-04 01:03

I am using Python 2.7.5 @ Mac OS X 10.9.3 with 8GB memory and 1.7GHz Core i5. I have tested time consumption as below.

d = {i:i*2 for i in xrange(10**7*3)} #WARN         


        
5条回答
  •  时光说笑
    2021-02-04 01:31

    Using for k,v in d.iteritems() with more descriptive names can make the code in the loop suite easier to read.

提交回复
热议问题