# Setting the display order of entries in (unordered) Dict

**URL:** https://discourse.julialang.org/t/setting-the-display-order-of-entries-in-unordered-dict/105954
**Category:** Performance
**Created:** [November 8, 2023, 2:52pm UTC](https://discourse.julialang.org/t/setting-the-display-order-of-entries-in-unordered-dict/105954 "2023-11-08T14:52:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)
#### Post date: [November 8, 2023, 2:52pm UTC](https://discourse.julialang.org/t/setting-the-display-order-of-entries-in-unordered-dict/105954/1 "2023-11-08T14:52:16Z")

</div>

Is there a way to designate what order the pairs of a Julai dictionary are displayed in (without using OrderedDict)?

Elaboration: StructuralIdentifiability.jl takes a model, and assesses the identifiability of each parameter and initial condition. The output is a dict, mapping each component to its identifiability. I am making an extension which applies its functions to reaction network models (declared by Catalyst). It works, but the output jumbles parameters and initial conditions a little bit all over the place. For the user, it would be easier to go through the output if they were in a specific order. So ideally I would like to remake the output Dict before it is sent to the user, fixing the order which things are displayed. However, given that StrucutrualIdentifaibility.jl’s functions outputs (unordered) Dictionaries, I want my output of these functions to output the same type (this feels sensible), and hence not use OrderedDictionaries. Also, I do not care about the order for iterating through the dict or similarly, this is all about how it is displayed.

I tried just creating a new dict, and setting the entires one by one in the designated order. Unfortunately, this did not work.

I realise this might not be possible, but figured I’d ask at least.

---

<div class="post-metadata">

### Author: ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)
#### Post date: [November 8, 2023, 3:01pm UTC](https://discourse.julialang.org/t/setting-the-display-order-of-entries-in-unordered-dict/105954/2 "2023-11-08T15:01:54Z")

</div>

A `Dict`’s display order is (almost certainly, but I’m speculating) based on its storage order. Because a `Dict` organizes keys by hash (for efficient lookup), this is not something you have good control over. Assembling the `Dict` in a different order will not affect the storage order in a predictable way and it would be subject to change over different versions anyway.

If this is just for display, consider collecting the `Dict` to another container where you have better control and instead display that. For example

```julia-repl
julia> sort(Dict(3 => 2, 1 => 4)) # OrderedDict
OrderedCollections.OrderedDict{Int64, Int64} with 2 entries:
  1 => 4
  3 => 2

julia> sort!(collect(Dict(3 => 2, 1 => 4))) # Vector{Pair}
2-element Vector{Pair{Int64, Int64}}:
 1 => 4
 3 => 2

```

---

<div class="post-metadata">

### Author: ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)
#### Post date: [November 8, 2023, 6:46pm UTC](https://discourse.julialang.org/t/setting-the-display-order-of-entries-in-unordered-dict/105954/3 "2023-11-08T18:46:48Z")

</div>

Sounds like what I feared is the case, and there isn’t really a solution without going to `OrderedDict`s ☹ . Thanks for the input!
