Forum Academy Marketplace Showcase Pricing Features

Sort a list by another list

Suppose I’ve got for some Object, two fields, each of which is a list of length N. For example

User.Items = [milk, bread, eggs]
User.Preferences = [2,1,10]

I’d like to sort the first list by the second via a backend workflow (I assume client-side is out of the question). So the updated User.Items = [eggs, milk, bread].

In other words I’ve got a list of tuples [(milk,2), (bread,1), (eggs,10)] and I’m trying to run a basic list comprehension. I’m using this “parallel lists” format because I can’t see another way to store the preference information for each user/item pair (short of creating a new database for each combination, but this would not scale at all with where my app is headed).

I’ve tried everything I can think of short of setting up an API to run this trivial operation on Lambda. I’ve dug around List Shifter but can’t see a way to make this happen with the functionality I can observe.

Any ideas appreciated!

You can do this in List Shifter, client side. Its SORT action allows you to sort one list by some arbitrary other list. (This is called a “mapped” sort.)


Thanks Keith! Have sent you a coffee :slight_smile:

1 Like

Much appreciated!

1 Like