>>>>> "GVW" == gvwilson <gvwilson@nevex.com> writes: GVW> On a semi-related note, can someone explain why programs are GVW> not allowed to iterate directly through the elements of a GVW> dictionary: GVW> for (key, value) in dict: ...body... Pythonic design rules #2: Explicit is better than implicit. There are at least three "natural" ways to interpret "for ... in dict:" In addition to the version that strikes you as most natural, some people also imagine that a for loop should iterate over the keys or the values. Instead of guessing, Python provides explicit methods for each possibility: items, keys, values. Yet another possibility, implemented in early versions of JPython and later removed, was to treat a dictionary exactly like a list: Call __getitem__(0), then 1, ..., until a KeyError was raised. In other words, a dictionary could behave like a list provided that it had integer keys. Jeremy
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