This just a little modification/alternate implementation of @griffpatch's list sorting algorithm based on insertion sort. The difference is that you can retrieve the original order of the items by looking up their index in the 'list_lookup' list (see the demo).
Original sorting algorithm by @griffpatch, the modification was made entirely by me.