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

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Sat, 17 Jun 2000 16:42:52 +0200


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?

</F>