Reputation: 481
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
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