[Python-Dev] Q: why doesn't list.extend use the sequence interface?

M.-A. Lemburg mal@lemburg.com
Sat, 17 Jun 2000 16:44:47 +0200


Fredrik Lundh wrote:
> 
> mal wrote:
> > The above looks a lot like an iterator... how about
> > providing a standard PySequence_Iterate(obj, callback)
> > with the callback being called for every element of the
> > sequence ?!
> 
> PySequence_Enumerate, perhaps?
>
> > The iterator could then be optimized for lists and tuples.
> > Not as fast as inlining, but a more generic solution...
> 
> more generic than useful, imo:
> 
>     - it's slower.
> 
>     - it's awkward to use: you need to put the state in a
>       structure, invert your program logic, etc.
> 
>     - it doesn't scale: what if you want to loop over two
>       structures?  what if you want to loop over two objects,
>       using two different indices?

Or perhaps, use a different iteration technique: the one
used by PyDict_Next(). It doesn't need a callback, but
instead plays with pointers you pass to it via output
variables.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/