fast sub list operations

Skip Montanaro skip at pobox.com
Tue Oct 16 08:50:13 EDT 2001


    Robin> I constantly miss some nice way to subset lists. As an example
    Robin> suppose I have a list of x y coordinates eg

    Robin>         [x0,y0,x1,y1,.....]

    Robin> and wish to perform the operation x->x+v, y->y+w for the
    Robin> co-ordinates in the list I don't seem to be able to do this fast
    Robin> using map.

I think most people will point you to NumPy.

    Robin> ... I don't seem to have an interlace to get back to the original
    Robin> list format.

Check out the zip builtin function:

    >>> zip([1,2,3],[7,8,9])
    [(1, 7), (2, 8), (3, 9)]

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list