# Say I have an array of symbols \`\[:w, :z, :c\]\` , how can I use it as a sorting ord

**URL:** <https://discourse.julialang.org/t/say-i-have-an-array-of-symbols-w-z-c-how-can-i-use-it-as-a-sorting-ord/54492>\
**Category:** General Usage\
**Created:** [February 2, 2021, 9:28pm UTC](https://discourse.julialang.org/t/say-i-have-an-array-of-symbols-w-z-c-how-can-i-use-it-as-a-sorting-ord/54492 "2021-02-02T21:28:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [February 2, 2021, 9:28pm UTC](https://discourse.julialang.org/t/say-i-have-an-array-of-symbols-w-z-c-how-can-i-use-it-as-a-sorting-ord/54492/1 "2021-02-02T21:28:53Z")

</div>

Say that I have an array of Tuples `[(:c, 2), (:z, 2), (:w, 2)]` and I want to sort it such that I get `[(:w, 2), (:z, 2), (:c, 2)]` , i.e. that the symbols are in the same order as in `[:w, :z, :c]`

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1612299985436900?thread_ts=1612299985.436900&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [February 2, 2021, 9:30pm UTC](https://discourse.julialang.org/t/say-i-have-an-array-of-symbols-w-z-c-how-can-i-use-it-as-a-sorting-ord/54492/2 "2021-02-02T21:30:39Z")

</div>

Here are two possible solutions:

```julia
x = [(:c, 2), (:z, 2), (:w, 2)];
t = [:w, :z, :c];
order = Dict([t[i] => i for i in 1:length(t)]);
sort(x, by = y -> order[first(y)])
3-element Array{Tuple{Symbol,Int64},1}:
 (:w, 2)
 (:z, 2)
 (:c, 2)

```

or

```julia
x = [(:c, 2), (:z, 2), (:w, 2)];
t = [:w, :z, :c];
sort(x, by = x->findfirst(y->y==first(x), t))

```
