On Mon, 20 Mar 2000, Jeremy Hylton wrote: > 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. Two remarks: Jeremy meant "consecutive natural keys starting with 0", (yes, I've managed to learn mind-reading from the timbot) and that (the following is considered a misfeature): import UserDict a = UserDict.UserDict() a[0]="hello" a[1]="world" for word in a: print word Will print "hello", "world", and then die with KeyError. I realize why this is happening, and realize it could only be fixed in Py3K. However, a temporary (though not 100% backwards compatible) fix is that "for" will catch LookupError, rather then IndexError. Any comments? -- Moshe Zadka <mzadka@geocities.com>. http://www.oreilly.com/news/prescod_0300.html http://www.linux.org.il -- we put the penguin in .com
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