Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use OrderedDict from DataStructures package in Julia?

Tags:

julia

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?

like image 860
jimjampez Avatar asked Dec 25 '22 08:12

jimjampez


1 Answers

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.

like image 53
DSM Avatar answered Mar 05 '23 05:03

DSM