iterators and views of lists
Terry Reedy
tjreedy at udel.edu
Sat Dec 19 03:15:06 EST 2009
On 12/19/2009 12:10 AM, Gregory Ewing wrote:
> Terry Reedy wrote:
>> On the other hand, Python indexes are a form of random access
>> iterator, the top of the hierarchy.
>
> The term "random access iterator" seems oxymoronic to
> me. Iteration is all about operating on things in
> sequence. If you're accessing elements arbitrarily,
> then you're not iterating.
>
>> Python, traditionally, only came with one mutable builtin sequence
>> type, so the sort function was made a method of that type.
>
> Also it probably operates rather more efficiently
> than a generic one would, as it doesn't have to go
> through a general mechanism to access elements, but
> can take advantage of its knowledge of the internal
> structure of a list.
I presume there is no array sort because it is O(n) to copy array to
list and back again with tolist and fromlist methods.
Anyone needed space-saving of in place in array can write array sort
with generic quicksort or whatever is appropriate to peculiarities of
specific data.
tjr
More information about the Python-list
mailing list