Adding a function to sort the mapped list based on some indices