How to use OrderedDict from DataStructures package in Julia?
-
21-12-2019 - |
Question
I am trying to install and use the DataStructures package and it doesn't seem to be working; or I am missing something.
Pkg.init()
Pkg.status()
Pkg.add("DataStructures")
Pkg.status()
Pkg.update()
d = OrderedDict(Char,Int)
ERROR: OrderedDict not defined
What's the problem?
Solution
Assuming you didn't get any errors you didn't mention, then you installed the package. Now you have to let Julia know you want to use it:
julia> using DataStructures
julia> d = OrderedDict{Char,Int}()
DataStructures.OrderedDict{Char,Int32}()
julia> d['a'] = 9
julia> d
['a'=>9]
If you'd prefer not to clutter the scope, you could use import
instead:
julia> import DataStructures
julia> DataStructures.OrderedDict{Char, Int8}()
DataStructures.OrderedDict{Char,Int8}()
or
julia> import DataStructures: OrderedDict
instead. Reading the Modules section of the manual might be helpful.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow