__getslice__

Stuart Reynolds S.I.Reynolds at cs.bham.ac.uk
Mon Nov 29 22:06:31 CET 1999


Hans Nowak wrote:
> 
...
> Did you try UnaryFnSequence(square, [2,3,4])? You'll get a surprising
> result:
> 
> ((0,0), (1,1), (2,4))
> 
> >     def __repr__(self):
> >         s='( '
> >         for x in range( len(self) ):
> >             s = s+'('+`x`+','+`self._fn(x)`+'), '
> >         return s[:-2] + ' )'
> 
> This is the culprit... You take a list of N elements, and then you
> loop over *a range 0..N-1*... rather than the list! Try replacing the
> 
>   for x in range(len(self)):
> 
> with
> 
>   for x in self._inputs:
> 
> This might do what you intended. ^_^
> 
> Hope this helps,

Nice one.

Cheers,

Stu




More information about the Python-list mailing list