# OrderedDict from OrderedCollections.jl

**URL:** <https://discourse.julialang.org/t/ordereddict-from-orderedcollections-jl/117283>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 20, 2024, 9:09pm UTC](https://discourse.julialang.org/t/ordereddict-from-orderedcollections-jl/117283 "2024-07-20T21:09:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottrsm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottrsm/32/208959_2.png) [@scottrsm](https://discourse.julialang.org/u/scottrsm)\
**Post date:** [July 20, 2024, 9:09pm UTC](https://discourse.julialang.org/t/ordereddict-from-orderedcollections-jl/117283/1 "2024-07-20T21:09:46Z")

</div>

I tried merging two OrderedDicts with merge (also with merge!). The resulting dictionary was of type OrderedDict but was not Ordered!!!

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [July 20, 2024, 9:34pm UTC](https://discourse.julialang.org/t/ordereddict-from-orderedcollections-jl/117283/2 "2024-07-20T21:34:01Z")

</div>

Can you give an example of the behavior you get and the behavior you expect?

To me it looks OK:

```julia
julia> using OrderedCollections

julia> d1 = OrderedDict("a" => 1, "b" => 2)
OrderedDict{String, Int64} with 2 entries:
  "a" => 1
  "b" => 2

julia> d2 = OrderedDict("c" => 3, "a" => 4)
OrderedDict{String, Int64} with 2 entries:
  "c" => 3
  "a" => 4

julia> merge!(d1, d2)
OrderedDict{String, Int64} with 3 entries:
  "a" => 4
  "b" => 2
  "c" => 3

```

Here all the order in `d1` is preserved and the new elements of `d2` are added at the end (which makes sense to me since I am inserting them later, via the `merge!` operation).

---

<div class="post-metadata">

**Author:** ![scottrsm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottrsm/32/208959_2.png) [@scottrsm](https://discourse.julialang.org/u/scottrsm)\
**Post date:** [July 20, 2024, 10:16pm UTC](https://discourse.julialang.org/t/ordereddict-from-orderedcollections-jl/117283/3 "2024-07-20T22:16:32Z")

</div>

My two dictionaries were Float64 to Float64.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 20, 2024, 10:35pm UTC](https://discourse.julialang.org/t/ordereddict-from-orderedcollections-jl/117283/4 "2024-07-20T22:35:04Z")

</div>

It’s probably worth noting that OrderedDict is ordered by insertion time, not value. You might be looking for a SortedDict.

---

<div class="post-metadata">

**Author:** ![scottrsm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottrsm/32/208959_2.png) [@scottrsm](https://discourse.julialang.org/u/scottrsm)\
**Post date:** [July 20, 2024, 10:38pm UTC](https://discourse.julialang.org/t/ordereddict-from-orderedcollections-jl/117283/5 "2024-07-20T22:38:11Z")

</div>

Thank you, that explains it.
