List transormation
Dale Strickland-Clark
dale at out-think.NOSPAMco.uk
Tue Sep 19 12:42:57 EDT 2000
Ah yes, map. I'd overlooked that.
Thanks
--
Dale Strickland-Clark
Out-Think Ltd, UK
Business Technology Consultants
Andy Smith <ams70 at cam.ac.uk> wrote in message
news:prdk8c8cp3i.fsf at beagle.eng.cam.ac.uk...
> "Dale Strickland-Clark" <dale at out-think.NOSPAMco.uk> writes:
>
> > 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']
>
> >>> map (lambda n: x[n], y)
> ['my', 'nose', 'is', 'a', 'kipper']
>
> This could be wrapped into a function taking arguments equivalent to x
> and y if you wanted to use it a lot.
>
> Andy
> --
> Andy Smith ams70 at cam.ac.uk
> St John's College, Cambridge, CB2 1TP, UK (07989) 453208
>
More information about the Python-list
mailing list