fast sub list operations

Robin Becker robin at jessikat.fsnet.co.uk
Tue Oct 16 13:39:30 EDT 2001


In article <3BCC4C52.7F0881A4 at letterror.com>, Just van Rossum
<just at letterror.com> writes
>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
I didn't actually choose the data structure. Actually in this case Just
the points are the lists of points from your Path class in
reportlab.graphics.shapes, but I guess you didn't choose the base
representation for lists of points either :-)
-- 
Robin Becker



More information about the Python-list mailing list