[Python-bugs-list] [ python-Bugs-805788 ] Minor Python Intro update
SourceForge.net
noreply at sourceforge.net
Thu Sep 18 14:15:32 EDT 2003
Bugs item #805788, was opened at 2003-09-14 00:40
Message generated for change (Comment added) made by loewis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=805788&group_id=5470
Category: Documentation
Group: None
Status: Open
Resolution: None
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: Martin v. Löwis (loewis)
Date: 2003-09-18 20: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