# If Items of list are equal then re-sort list by other function

**URL:** <https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152>\
**Category:** Uncategorized\
**Created:** [August 31, 2019, 5:04pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152 "2019-08-31T17:04:31Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![D.CHRISTIDIS](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@D.CHRISTIDIS](https://forum.dynamobim.com/u/D.CHRISTIDIS)\
**Post date:** [August 31, 2019, 5:04pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/1 "2019-08-31T17:04:31Z")

</div>

Dear dynamo users, it’s been troubling me all day. I have a list of points. I want to sort them by the value of their X coordinate. If their x value is equal I want to sort them by their distance to another point. I really don’t know how to handle that.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/b/0b4bcdcb38f90d6ffd1453298039f3f34d33da65.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:** [August 31, 2019, 5:19pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/2 "2019-08-31T17:19:08Z")

</div>

> [@D.CHRISTIDIS](#):
>
> If their x value is equal I want to sort them by their distance to another point.

X values equal to what?

---

<div class="post-metadata">

**Author:** ![D.CHRISTIDIS](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@D.CHRISTIDIS](https://forum.dynamobim.com/u/D.CHRISTIDIS)\
**Post date:** [August 31, 2019, 5:19pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/3 "2019-08-31T17:19:45Z")

</div>

equal to one another. Sorry I should have specified that.

---

<div class="post-metadata">

**Author:** ![D.CHRISTIDIS](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@D.CHRISTIDIS](https://forum.dynamobim.com/u/D.CHRISTIDIS)\
**Post date:** [August 31, 2019, 5:20pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/4 "2019-08-31T17:20:15Z")

</div>

If they are the same to be more accurate

---

<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:** [August 31, 2019, 5:20pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/5 "2019-08-31T17:20:35Z")

</div>

> [@D.CHRISTIDIS](#):
>
> Sorry I should have specified that.

Yes please and show complete graph with all the previews visible.

---

<div class="post-metadata">

**Author:** ![D.CHRISTIDIS](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@D.CHRISTIDIS](https://forum.dynamobim.com/u/D.CHRISTIDIS)\
**Post date:** [August 31, 2019, 5:27pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/6 "2019-08-31T17:27:02Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/d/7d32aaddb8cb4473e677ef7cd004fa42349eedfd.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:** [August 31, 2019, 6:03pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/7 "2019-08-31T18:03:47Z")

</div>

Similar topic discussed here:

> [@Closest point for given point sorting loop](https://forum.dynamobim.com/t/closest-point-for-given-point-sorting-loop/12600):
>
> Hi dynamo users. I stucked with idea of loop that can sort the points by distance but not from just one point: -\>Starting with starting point and point collection,-\> then find closest point to the starting then take the found one and repeat the search of closest one. Then sort it in found order. I tried with loop while node after I created custom node that giving the closest point and rest of collection. Ty for help!.

---

<div class="post-metadata">

**Author:** ![D.CHRISTIDIS](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@D.CHRISTIDIS](https://forum.dynamobim.com/u/D.CHRISTIDIS)\
**Post date:** [August 31, 2019, 6:39pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/8 "2019-08-31T18:39:48Z")

</div>

I still have a basic question. How can I compare items of the same list? How do I say if items of list are the same get index of items? I simply cannot figure that out.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [August 31, 2019, 7:31pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/9 "2019-08-31T19:31:23Z")

</div>

Try a List.GroupByKey node. Then get the distance from each sublist of points to the ‘point of interest’, and sort the sublists using a List.SortByKey (all inputs should be @L2).

---

<div class="post-metadata">

**Author:** ![D.CHRISTIDIS](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@D.CHRISTIDIS](https://forum.dynamobim.com/u/D.CHRISTIDIS)\
**Post date:** [August 31, 2019, 7:33pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/10 "2019-08-31T19:33:47Z")

</div>

Thank you very much for the response. What would the key be in the case of the same items in list?

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [August 31, 2019, 7:36pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/11 "2019-08-31T19:36:12Z")

</div>

Build the graph. By using a group by key node first you have sublists which contain only matching values. You might want to add a List.SortByKey node first (thought you had that much.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [August 31, 2019, 7:40pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/12 "2019-08-31T19:40:53Z")

</div>

Also, don’t spend the ram sorting by index by value. The values will sort themselves out just fine.

PS: no need to multi-post in 3 threads for the same problem. Just makes more convoluted conversations. Let’s leave all posts on this in this topic.

---

<div class="post-metadata">

**Author:** ![D.CHRISTIDIS](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@D.CHRISTIDIS](https://forum.dynamobim.com/u/D.CHRISTIDIS)\
**Post date:** [August 31, 2019, 7:55pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/13 "2019-08-31T19:55:25Z")

</div>

I tried to split the problem in order to get more specific answers. Unfortunately, i still haven’t understood the input for the Keys in order to group separately the same items.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [August 31, 2019, 10:50pm UTC](https://forum.dynamobim.com/t/if-items-of-list-are-equal-then-re-sort-list-by-other-function/40152/14 "2019-08-31T22:50:06Z")

</div>

What have you tried?
