[Tutor] Why isn't iteritems() working when items() does?

Jim Mooney cybervigilante at gmail.com
Sun Apr 28 04:21:46 CEST 2013


#Changing a dictionary into a 2-tuple list with the items method
works, as per the
#first example. But using iteritems returns an error - using Py33

dick = {'villain': 'Roderigo', 'hero': 'Othello', 'friend': 'Cassio',
'beauty':'Desdemona'}

dickList = dick.items()
for role, name in dickList:
    print(role, name)

#The above works, but using iteritems() in place of items doesn't

dickList2 = dick.iteritems()
for role, name in dickList2:
    print(role, name)

#error: builtins.AttributeError: 'dict' object has no attribute 'iteritems'

-- 
Jim Mooney

Texting a program as he drove, John inadvertently dereferenced a null
pointer, and a huge crash ensued.

The good thing about crocodile farts is few of us feel the need to get
that close to a crocodile.


More information about the Tutor mailing list