[Tutor] Two questions [array out of bounds / lazylist / autovivification]

Kirby Urner urnerk@qwest.net
Sun, 14 Apr 2002 08:32:54 -0400


On Sunday 14 April 2002 04:16 am, Danny Yoo wrote:

> ###
> class lazylist(list):
>     def __getitem__(self, i):
>         if not (type(i) is tuple):
>             self.padExpand(i)
>         return list.__getitem__(self, i)

Hi Danny -- could you please explain why you are making sure
i is not a tuple here, and in __setitem__.

Also, I notice that asking for l[5] changes a 3-element list to have
5 elements, yet returns nothing, whereas l[5:6] returns the empty
list and does not change it.  This might seem inconsistent, but 
is perhaps intentional.

In any case, this was an instructive example of subclassing a
builtin.

Kirby