[Tutor] dict.iteritems() in Python3, was Re: Tutor Digest, Vol 110, Issue 117
Prasad, Ramit wrote: Jim Mooney wrote: In py3.x, iteritems was replaced by .items() Interesting, since iteritems was in my book, which was updated for Py33. I guess the moral is you shouldn't trust an author 100% ;') I must admit, iteritems did seem awkward and annoying so I'm glad it's dropped. Jim Technically, .items() was dropped and .iteritems() was renamed .items() One way to verify that is to run $ cat tmp.py d = dict(a=1, b=2) x = d.items() y = d.iteritems() z = d.viewitems() through the 2to3 tool: $ 2to3 tmp.py 2 /dev/null --- tmp.py (original) +++ tmp.py (refactored) @@ -1,5 +1,5 @@ d = dict(a=1, b=2) -x = d.items() -y = d.iteritems() -z = d.viewitems() +x = list(d.items()) +y = iter(d.items()) +z = d.items() So d.items() -- list(d.items()) d.iteritems() -- iter(d.items()) d.viewitems() -- d.items() In short: items() and iteritems() were both dropped, and viewitems() was renamed items(). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dict.iteritems() in Python3, was Re: Tutor Digest, Vol 110, Issue 117
Peter Otten wrote: Prasad, Ramit wrote: Jim Mooney wrote: In py3.x, iteritems was replaced by .items() Interesting, since iteritems was in my book, which was updated for Py33. I guess the moral is you shouldn't trust an author 100% ;') I must admit, iteritems did seem awkward and annoying so I'm glad it's dropped. Jim Technically, .items() was dropped and .iteritems() was renamed .items() One way to verify that is to run $ cat tmp.py d = dict(a=1, b=2) x = d.items() y = d.iteritems() z = d.viewitems() through the 2to3 tool: $ 2to3 tmp.py 2 /dev/null --- tmp.py (original) +++ tmp.py (refactored) @@ -1,5 +1,5 @@ d = dict(a=1, b=2) -x = d.items() -y = d.iteritems() -z = d.viewitems() +x = list(d.items()) +y = iter(d.items()) +z = d.items() So d.items() -- list(d.items()) d.iteritems() -- iter(d.items()) d.viewitems() -- d.items() In short: items() and iteritems() were both dropped, and viewitems() was renamed items(). Thanks for the excellent (and well laid out) correction Peter! ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dict.iteritems() in Python3, was Re: Tutor Digest, Vol 110, Issue 117
On Tue, Apr 30, 2013 at 1:44 PM, Peter Otten __pete...@web.de wrote: d.items() -- list(d.items()) d.iteritems() -- iter(d.items()) d.viewitems() -- d.items() In short: items() and iteritems() were both dropped, and viewitems() was renamed items(). Following on from this, the iterator types weren't dropped, but iteritems, iterkeys, itervalues were removed from the mapping API. iter(d.items()) returns an item iterator similar to the old d.iteritems(), but the name was corrected from the weird 'dictionary-' prefix to simply 'dict_'. Also, even though it's instantiated by a view, the 3.x iterator references the dict directly, not the view. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor