对字典进行排序

julia> d
Dict{Char,Int64} with 3 entries:
  'a' => 10
  'c' => 8
  'b' => 21

现在如何按照字典的键或者值对字典进行排序?

hash 表实现的字典是无序的

Dict([itr])

Dict{K,V}() constructs a hash table with keys of type K and values of type V.
Keys are compared with isequal and hashed with hash.

你可能想要

ref:—— A Dict preserving the insertion order? - Usage - JuliaLang

DataStructures.jl 里面还有个SortedDict

字典的关键就是不需要排序。但是

sort(collect(d), by = x->x[1])

应该可以

1 个赞