This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Minor Python Intro update
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: average, fdrake, loewis
Priority: normal Keywords:

Created on 2003-09-13 22:40 by average, last changed 2022-04-10 16:11 by admin. This issue is now closed.

Messages (3)
msg18157 - (view) Author: Mark J (average) Date: 2003-09-13 22:40
The little source code on the following web page 
demonstrates outdated patterns:

http://python.org/doc/Introduction.html

def invert(table):
    index = {}                # empty dictionary
    for key in table.keys():
        value = table[key]
        if not index.has_key(value):
            index[value] = [] # empty list
        index[value].append(key)
    return index

Perhaps the following would be cleaner:

def invert(table):
    index = {}                # empty dictionary
    for key in table: #"for key, value in table.iteritems():"?
        value = table[key]
        if value not in index:
            index[value] = [] # empty list
        index[value].append(key)
    return index

msg18158 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-09-18 18:15
Logged In: YES 
user_id=21627

I fail to see the problem. The code is not outdated, it
continues to work just fine. As for clarity, I find explicit
usage of .keys() and .has_key() clearer than with your
proposed change. Explicit is better than implicit.
msg18159 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2003-09-23 20:15
Logged In: YES 
user_id=3066

Martin's right; there's no clear reason to make the
suggested change.  Closing the report.
History
Date User Action Args
2022-04-10 16:11:09adminsetgithub: 39229
2003-09-13 22:40:15averagecreate