A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-September/056379.html below:

[Python-Dev] PEP 3000 and iterators

[Python-Dev] PEP 3000 and iterators [Python-Dev] PEP 3000 and iteratorsGuido van Rossum guido at python.org
Mon Sep 12 16:37:30 CEST 2005
On 9/11/05, Delaney, Timothy (Tim) <tdelaney at avaya.com> wrote:
> James Y Knight wrote:
> 
> > Just to be clear, I do not want nor expect this. I wish to be able to
> > specifically modify code with full knowledge of what has changed in
> > Py3.0 such that it will work with both Py2.X and Py3.0.
> 
> If you want these things to work in 2.x and 3.0, just use
> iter(dict_instance) and list(dict_instance) as appropriate.

Simpler still, just use di.keys() but make sure you're only using the
result to iterate over once without modifying the dict's key set. Or
if you *have* to avoid creating a list in Py2.x, write your code to
iterate over the dict itself even if you'd like itervalues or
iteritems; you can always get the value explicitly by indexing the
dict.

IOW use the API whose name will remain but don't rely on the
functionality that will change.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4