Gibt es relevante Unterschiede zwischen dict.items()
y dict.iteritems()
?
De la Python-Dokumente :
dict.items()
: Rückgabe a kopieren. der Liste der Paare (Schlüssel, Wert) des Wörterbuchs.
dict.iteritems()
: Rückgabe eines Iterator über die Paare des Wörterbuchs (Schlüssel, Wert).
Wenn ich den folgenden Code ausführe, scheint jeder einen Verweis auf dasselbe Objekt zurückzugeben. Gibt es irgendwelche feinen Unterschiede, die ich übersehe?
#!/usr/bin/python
d={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'
Ausgabe:
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