性夜影院午夜看片,无码精品久久一区二区三区,婷婷成人丁香五月综合激情,校园春色 qvod,性调教室高h学校

【Python面試真題】- 對(duì)比一下dict中items與iteritems?

 D = {'a':1,'b':2,'c':3,'d':4}    
 D.items()                       #一次性取出所有    
[('a', 1), ('c', 3), ('b', 2), ('d', 4)]    
 D.iteritems()                   #迭代對(duì)象,每次取出一個(gè)。用for循環(huán)遍歷出來(lái);    
    
 for i in D.iteritems():    
…   print i,    
…    
('a', 1) ('c', 3) ('b', 2) ('d', 4)    
 for k,v in D.iteritems():    
…   print k,    
…    
a c b d    
總結(jié):   
1. 一般iteritems()迭代的辦法比items()要快,特別是數(shù)據(jù)庫(kù)比較大時(shí)。  

2. 在Python3中一般取消前者函數(shù)  



相關(guān)新聞

歷經(jīng)多年發(fā)展,已成為國(guó)內(nèi)好評(píng)如潮的Linux云計(jì)算運(yùn)維、SRE、Devops、網(wǎng)絡(luò)安全、云原生、Go、Python開發(fā)專業(yè)人才培訓(xùn)機(jī)構(gòu)!