fast sub list operations

Just van Rossum just at letterror.com
Tue Oct 16 11:03:47 EDT 2001


Robin Becker wrote:
> 
> I constantly miss some nice way to subset lists. As an example suppose I
> have a list of x y coordinates eg
> 
>         [x0,y0,x1,y1,.....]
>
> and wish to perform the operation x->x+v, y->y+w for the co-ordinates in
> the list I don't seem to be able to do this fast using map. Even if I
> had a way to slice the list nicely into
> 
> X=[x0,x1,.....x(n-1)] & Y=[y0,y1,.....,y(n-1)]
> 
> so that I can do map(operator.add,X,n*[v]) to perform the arithmetic
> quickly I don't seem to have an interlace to get back to the original
> list format.
> 
> How can these kinds of operations be performed quickly in current python
> and what if any new features would python require to do them best?

Your problem is not with missing Python features but with your data
structure. Why not use [(x0, y0), (x1, y1), ...] instead?

Just



More information about the Python-list mailing list