# Sort a list by another list

**URL:** <https://forum.bubble.io/t/sort-a-list-by-another-list/145097>\
**Category:** Need help\
**Created:** [April 7, 2021, 2:37am UTC](https://forum.bubble.io/t/sort-a-list-by-another-list/145097 "2021-04-07T02:37:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![orowa](https://avatars.discourse-cdn.com/v4/letter/o/e9c0ed/32.png) [@orowa](https://forum.bubble.io/u/orowa)\
**Post date:** [April 7, 2021, 2:37am UTC](https://forum.bubble.io/t/sort-a-list-by-another-list/145097/1 "2021-04-07T02:37:54Z")

</div>

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](http://forum.bubble.io/t/list-shifter-reverse-rotate-swap-and-iterate-loop-over-bubble-lists-now-at-v1-4-adds-numeric-option-get-index-action/56237/78) but can’t see a way to make this happen with the functionality I can observe.

Any ideas appreciated!

---

<div class="post-metadata">

**Author:** ![keith](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/keith/32/56020_2.png) [@keith](https://forum.bubble.io/u/keith)\
**Post date:** [April 7, 2021, 10:14pm UTC](https://forum.bubble.io/t/sort-a-list-by-another-list/145097/2 "2021-04-07T22:14:43Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![orowa](https://avatars.discourse-cdn.com/v4/letter/o/e9c0ed/32.png) [@orowa](https://forum.bubble.io/u/orowa)\
**Post date:** [April 8, 2021, 3:37pm UTC](https://forum.bubble.io/t/sort-a-list-by-another-list/145097/3 "2021-04-08T15:37:28Z")

</div>

Thanks Keith! Have sent you a coffee 🙂

---

<div class="post-metadata">

**Author:** ![keith](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/keith/32/56020_2.png) [@keith](https://forum.bubble.io/u/keith)\
**Post date:** [April 8, 2021, 3:48pm UTC](https://forum.bubble.io/t/sort-a-list-by-another-list/145097/4 "2021-04-08T15:48:18Z")

</div>

Much appreciated!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [June 16, 2021, 2:38am UTC](https://forum.bubble.io/t/sort-a-list-by-another-list/145097/5 "2021-06-16T02:38:50Z")

</div>

This topic was automatically closed after 70 days. New replies are no longer allowed.
