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

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:) (More Info)

Here are two possible solutions:

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)


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