Iteration and large lists (was: Re: [Edu-sig] How to Improve code performance)

Dethe Elza dethe@burningtiger.com
Tue, 30 Oct 2001 14:17:20 -0800


> The PatternedList class is easy to implement _except_ that I don't
> think a user-defined object -- other than a subclass of UserList --
> can be used in a "for" loop.  UserList doesn't seem to help here,
> because it doesn't actually allow you to override the element lookup
> behavior of the list, to change the way the list is represented in
> memory.


Any ordered sequence type can be used in a "for" loop.  Built-in types 
which qualify include list, tuple, and string.  There are lots of 
additional sequence types in the libraries, such as UserList (no longer 
needed as of ver. 2.2 since you can subclass built-in types directly). 
Generally speaking, any class or type which implements __getitem__(self, 
key) with a numeric key should work in a "for" loop.

-- 

Dethe Elza (delza@burningtiger.com)
Chief Mad Scientist
Burning Tiger Technologies (http://burningtiger.com)
Living Code Weblog (http://livingcode.ca)