[Tutor] Why isn't iteritems() working when items() does?
Mitya Sirenef
msirenef at lightbird.net
Sun Apr 28 04:29:08 CEST 2013
On 04/27/2013 10:21 PM, Jim Mooney wrote:
> #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'
>
In py3.x, iteritems was replaced by .items()
-m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
More information about the Tutor
mailing list