iterators and views of lists

Brendan Miller catphive at catphive.net
Wed Dec 16 02:48:04 EST 2009


On Tue, Dec 15, 2009 at 9:09 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 12/15/2009 10:39 PM, Brendan Miller wrote:
>> I'm wondering if anyone has done work towards creating more powerful
>> iterators for python, or creating some more pythonic equivalent.
>
> For sequences, integer indexes let you do anything you want that the
> container supports.

No, that's what I'm getting at... Most of the existing mutating
algorithms in python (sort, reverse) operate over entire collections,
not partial collections delimited by indexes... which would be really
awkward anyway.

Currently people slice and dice with well... slices, but those are
copying, so if you want to operate over part of a range you make a
copy, perform the operation, then copy the results back in.

I was thinking you'd want something like random access iterators in
c++, or pointers in c, to write typical in place algorithmic code. To
me, something like non-copying slices (maybe you'd call it a list
view?) would seem functionally similar and maybe more pythonic.



More information about the Python-list mailing list