Issue 805788: Minor Python Intro update (original) (raw)
Issue805788
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) * ![]() |
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) ![]() |
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:09 | admin | set | github: 39229 |
2003-09-13 22:40:15 | average | create |