False error?

can this be true?:

MethodError: no method matching sort!(::Dict{Int64,String})

that seems to be basic thing, am I doing something wrong?

Regards,

Alar Aints,

Dicts are unordered, so you cannot sort them.
OrderedDicts are ordered, so you can sort them.

julia> using OrderedCollections

julia> d = OrderedDict(1 => :a, 4 => :b, 3 => :c, 2 => :d)
OrderedDict{Int64,Symbol} with 4 entries:
  1 => :a
  4 => :b
  3 => :c
  2 => :d

julia> sort!(d)
OrderedDict{Int64,Symbol} with 4 entries:
  1 => :a
  2 => :d
  3 => :c
  4 => :b

julia> d
OrderedDict{Int64,Symbol} with 4 entries:
  1 => :a
  2 => :d
  3 => :c
  4 => :b

Thanks, so how do I get it?
I typed:
using Pkg
Pkg.add(“OrderedCollections.jl”)
I got:
julia> Pkg.add(“OrderedCollections.jl”)

Cloning default registries into ~/.julia

Cloning registry from “https://github.com/JuliaRegistries/General.git

Added registry General to ~/.julia/registries/General

ERROR: The following package names could not be resolved:

  • OrderedCollections.jl (not found in project, manifest or registry)

Please specify by known name=uuid.

Try:

Pkg.add(“OrderedCollections”)

Thanks, works. :slight_smile: