List transormation

Bjorn Pettersen bjorn at roguewave.com
Tue Sep 19 15:00:57 EDT 2000


With Python 2.0 you can do:

Python 2.0b1 (#4, Sep  7 2000, 02:40:55) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> x = ['kipper', 'my', 'a', 'nose', 'is']
>>> y = [1, 3, 4, 2, 0]
>>> [x[n] for n in y]
['my', 'nose', 'is', 'a', 'kipper']
>>>

which is equivalent to the map solutions others have posted...

-- bjorn

Dale Strickland-Clark wrote:
> 
> Before I waste too much time on this, reinventing the wheel, is there a
> quick way to reorder the items in a list under the control of another list?
> 
> e.g..
> 
> x = ['kipper', 'my', 'a', 'nose', 'is']
> y = [1, 3, 4, 2, 0]
> 
> y transforms the order of x to produce:
> 
> ['my', 'nose', 'is', 'a', 'kipper']
> 
> Thanks
> 
> --
> Dale Strickland-Clark
> Out-Think Ltd, UK
> Business Technology Consultants
> 
> --
> http://www.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list