[Python-bugs-list] [ python-Bugs-805788 ] Minor Python Intro update

SourceForge.net noreply at sourceforge.net
Tue Sep 23 16:15:54 EDT 2003


Bugs item #805788, was opened at 2003-09-13 18:40
Message generated for change (Comment added) made by fdrake
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=805788&group_id=5470

Category: Documentation
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Mark J (average)
Assigned to: Nobody/Anonymous (nobody)
Summary: Minor Python Intro update

Initial Comment:
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





----------------------------------------------------------------------

>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2003-09-23 16:15

Message:
Logged In: YES 
user_id=3066

Martin's right; there's no clear reason to make the

suggested change.  Closing the report.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2003-09-18 14:15

Message:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=805788&group_id=5470



More information about the Python-bugs-list mailing list