# Sort groups by sorted keys

**URL:** <https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767>\
**Category:** Lists-Logic\
**Created:** [September 11, 2018, 9:48am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767 "2018-09-11T09:48:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbrision](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@rbrision](https://forum.dynamobim.com/u/rbrision)\
**Post date:** [September 11, 2018, 9:48am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/1 "2018-09-11T09:48:52Z")

</div>

Hi, i am a beginner on dynamo and would like to know how i can use a sorted list to sort another one… !

 ![dyna](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/d/3d0d6c3c18d6bfddb229be3270b865382f3d4dc3.jpeg)  
Thanks per advance !!

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [September 11, 2018, 9:51am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/2 "2018-09-11T09:51:00Z")

</div>

List.SortByKey

Sorting a list by a key… And please use screenshots not potato-phone-pictures… It physically hurts the eyes

---

<div class="post-metadata">

**Author:** ![rbrision](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@rbrision](https://forum.dynamobim.com/u/rbrision)\
**Post date:** [September 11, 2018, 9:51am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/3 "2018-09-11T09:51:53Z")

</div>

Iam really sorry for the bad pic ☹

---

<div class="post-metadata">

**Author:** ![rbrision](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@rbrision](https://forum.dynamobim.com/u/rbrision)\
**Post date:** [September 11, 2018, 9:56am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/4 "2018-09-11T09:56:53Z")

</div>

Sorry but list. Sortbykey doesn’t seem to work…

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [September 11, 2018, 9:57am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/5 "2018-09-11T09:57:55Z")

</div>

Hi,

Please post your error and proper screenshot 🙂

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [September 11, 2018, 10:12am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/6 "2018-09-11T10:12:49Z")

</div>

Alternatively you can (instead of grouping and sorting separately (it works either way)) use the Orchid node…  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/a/6a7edf6e32087b77041d26d761f96e17944f2e03.png)

But as you’re working with lists-within-lists-within-lists… you NEED to use list levels a lot.

---

<div class="post-metadata">

**Author:** ![rbrision](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@rbrision](https://forum.dynamobim.com/u/rbrision)\
**Post date:** [September 11, 2018, 11:54am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/7 "2018-09-11T11:54:19Z")

</div>

![dyna](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/d/3d0d6c3c18d6bfddb229be3270b865382f3d4dc3.jpeg)

Unfortunately i can’t get what i want , even when playing with the levels… 😕

Thanks for your advices anyway !

---

<div class="post-metadata">

**Author:** ![rbrision](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@rbrision](https://forum.dynamobim.com/u/rbrision)\
**Post date:** [September 11, 2018, 1:07pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/8 "2018-09-11T13:07:09Z")

</div>

Any idea of a solution ?

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [September 11, 2018, 1:20pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/9 "2018-09-11T13:20:16Z")

</div>

Don’t know what to tell ya… Not without your dateset anyway…

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/5/558e24e616a789967c849629bf08848492f21a9a.png)

---

<div class="post-metadata">

**Author:** ![rbrision](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@rbrision](https://forum.dynamobim.com/u/rbrision)\
**Post date:** [September 11, 2018, 1:50pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/10 "2018-09-11T13:50:41Z")

</div>

Thanks for the test but even in yours, the result at the end is not the one expected:  
elements in your watch node are in the wrong order , the right result should have been:  
element1,element2,element3,e4 and ,e5,e6,e7…  
instead of  
e1, e3, e2, e4 & e7,e6,e5…  
Sorry 😕

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [September 11, 2018, 1:57pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/11 "2018-09-11T13:57:32Z")

</div>

> [@rbrision](#):
>
> element1,element2,element3,e4 and ,e5,e6,e7…  
> instead of  
> e1, e3, e2, e4 & e7,e6,e5…  
> Sorry 😕

Why so ? The elements are sorted in a way that the orders are sorted.

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [September 11, 2018, 1:59pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/12 "2018-09-11T13:59:43Z")

</div>

> [@rbrision](#):
>
> in the wrong order

No… They are exactly as expected… the order is sorted from assumed to be unsorted in the beginning… and elements taking the places corresponding to the sorting of the corrected order…

So the final order is exactly as one would expect…

---

<div class="post-metadata">

**Author:** ![rastermadre](https://avatars.discourse-cdn.com/v4/letter/r/dfb087/32.png) [@rastermadre](https://forum.dynamobim.com/u/rastermadre)\
**Post date:** [September 11, 2018, 2:50pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/13 "2018-09-11T14:50:26Z")

</div>

A colleague of mine created a node for this: (RHA\_Utilities package, credit:Rami Hamati)

 ![double%20sort](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/6/b68286b46c2da4015d45522fcc82c441cfe482fb.jpeg)

---

<div class="post-metadata">

**Author:** ![rbrision](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@rbrision](https://forum.dynamobim.com/u/rbrision)\
**Post date:** [September 11, 2018, 3:25pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/14 "2018-09-11T15:25:11Z")

</div>

Thank you for your advices guyzz.  
But my goal is not achieved, maybe i havent very well explained what i aim for.

 ![Capture77](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/b/eb144a66f404aaba9d263f4cb9acd8b4c741abd4.jpeg)

My Goal is to obtain the list 1 in the order of the list 2. Maybe because as a grasshopper user my logic is different but i don’t understand why in every solution you purpose i never get what i want … !!!

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [September 11, 2018, 3:28pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/15 "2018-09-11T15:28:48Z")

</div>

Do you want to do something like this ? If it is only sorting your rooms another way…

> [@Sorting Curve List A by Curve List B](https://forum.dynamobim.com/t/sorting-curve-list-a-by-curve-list-b/25774/5):
>
> Edit : Same method as Alban, really [Capture]

---

<div class="post-metadata">

**Author:** ![rbrision](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@rbrision](https://forum.dynamobim.com/u/rbrision)\
**Post date:** [September 11, 2018, 3:45pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/16 "2018-09-11T15:45:25Z")

</div>

@mellouze

Thanks for your comment, but as you can see the number of the rooms are now completely diffrent from the initial list. It has taken only one item of the right “Level” and repeated it …Nice try but this is still not the expected result ! 🙂

 ![dyna2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/5/4597922f2ead55f8d5ac7b4ef27875b9e20c06e9.jpeg)

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [September 11, 2018, 3:48pm UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/17 "2018-09-11T15:48:21Z")

</div>

Use **List.UniqueItems** on your keys and use **List.AllIndexOf** instead. It should work if you tweak a little bit your graph.

Try things on your own and experiment with Dynamo. Only that why you’ll progress 😉

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [September 12, 2018, 6:00am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/18 "2018-09-12T06:00:35Z")

</div>

Have you tried SortByFunction? I know it is in 2.0, not sure about earlier Dynamo versions.

 ![sortbyfunction](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/b/0b77a73984edb82f76a4c52cd17af536d5753126.png)

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [September 12, 2018, 7:02am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/19 "2018-09-12T07:02:54Z")

</div>

Hi @kennyb6

You could also use @ListLevel to avoid **List.Sort** node:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/8/38665a623d5b474544a72f8d8e0529ab5f58175b.png)

---

<div class="post-metadata">

**Author:** ![Mitesh\_Gajjar](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@Mitesh\_Gajjar](https://forum.dynamobim.com/u/Mitesh_Gajjar)\
**Post date:** [September 18, 2018, 11:23am UTC](https://forum.dynamobim.com/t/sort-groups-by-sorted-keys/25767/20 "2018-09-18T11:23:27Z")

</div>

@rbrision

You can try something like this!!!

 ![test](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/1/517e84bb03f1cc6f67115b7fde51c2aa4e80db84.jpeg)

Mitesh
