命令项()和命令迭代项()之间有什么区别?
dict.items()
dict.iteritems()
?
dict.items()
*返回a 复制字典的(键,值)对的列表。
dict.iteritems()
*返回 迭代器在字典的(键,值)对上。
#!/usr/bin/pythond={1:'one',2:'two',3:'three'}print 'd.items():'for k,v in d.items(): if d[k] is v: print '\tthey are the same object' else: print '\tthey are different'print 'd.iteritems():' for k,v in d.iteritems(): if d[k] is v: print '\tthey are the same object' else: print '\tthey are different'
d.items(): they are the same object they are the same object they are the same object d.iteritems(): they are the same object they are the same object they are the same object
相关分类