hdrz
hdrz

Reputation: 481

Reorder a list 'in place', according to another list

How can I reorder a list in python according to another list, but without creating a new list, since it is linked by several objects?

This question and it's answers create new lists, so they don't apply.

Upvotes: 2

Views: 242

Answers (1)

Vaughn Cato
Vaughn Cato

Reputation: 64308

You can create the list however you want, and then reassign the elements. For example:

 X[:] = [x for (y,x) in sorted(zip(Y,X))]

Upvotes: 3

Related Questions