Ordered arrays

If I have a Dict:

P=Dict(“F1”=>(“a30”, “a37”), “F2”=>(“a10”, “a11”, “a12”),
“F3”=>(“a15”, “a22”, “a31”))
how to make it ordered - when it is used to be used by order - F1,F2,F3…?
Thank you!
Marco

Two options:

  1. make it an array of pairs, which is absolutely possible
P = [“F1”=>(“a30”, “a37”), “F2”=>(“a10”, “a11”, “a12”),
“F3”=>(“a15”, “a22”, “a31”)]
  1. use an OrderedDict from OrderedCollections.jl or DataStructures.jl
4 Likes

Hvala Zlajo!

Please, advice in case of following error:
ERROR: LoadError: MethodError: no method matching getindex(::OrderedSet{String}, ::UnitRange{Int64})
Closest candidates are:
getindex(::OrderedSet, ::Int64) at C:\Users\mmill.julia\packages\OrderedCollections\P6ntV\src\ordered_set.jl:78

Please post example code in backticks

``` 
like this, code here
```

You problably want d.[[1, 2, 3]] . Notice the broadcasting, the d. rather than d[[1, 2, 3]].

2 Likes