# \#dictionaries

**URL:** https://discourse.julialang.org/tag/dictionaries/825.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Dictionary for thread-safe, limited memoization](https://discourse.julialang.org/t/dictionary-for-thread-safe-limited-memoization/137072)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 25\
**Last updated:** [May 27, 2026, 10:14pm UTC](https://discourse.julialang.org/t/dictionary-for-thread-safe-limited-memoization/137072 "2026-05-27T22:14:14Z")

</div>

I am looking for a Dict-like type which allows me to keep only the last N values inserted, for some value of N::Int, is thread-safe. Background: memoization, where the resulting objects are large and I am unlike…

---

## [How to better initialize a dictionary containing multidimensional array?](https://discourse.julialang.org/t/how-to-better-initialize-a-dictionary-containing-multidimensional-array/129632)

<div class="topic-metadata">

**Author:** [@Harrykjg-physics](https://discourse.julialang.org/u/Harrykjg-physics)\
**Replies:** 10\
**Last updated:** [June 4, 2025, 11:52am UTC](https://discourse.julialang.org/t/how-to-better-initialize-a-dictionary-containing-multidimensional-array/129632 "2025-06-04T11:52:38Z")

</div>

Hi everyone, I want to create a Dict() object where the keys are NTuple{6, Int} and the corresponding values are rank-6 arrays. I found the following function to create such Dict object with 64 items are much slower than…

---

## [Get an equal element of a set/get an equal key of a dictionary](https://discourse.julialang.org/t/get-an-equal-element-of-a-set-get-an-equal-key-of-a-dictionary/128779)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 4\
**Last updated:** [May 7, 2025, 3:52pm UTC](https://discourse.julialang.org/t/get-an-equal-element-of-a-set-get-an-equal-key-of-a-dictionary/128779 "2025-05-07T15:52:26Z")

</div>

Suppose I have x and s::AbstractSet and I know x ∈ s. How to get the element of s, say e, such that x == e? I could iterate through all elements like this, but surely there should be a simpler and more efficient solution…

---

## [Custom dictionary type: fieldless keytype, fieldless valtype](https://discourse.julialang.org/t/custom-dictionary-type-fieldless-keytype-fieldless-valtype/128405)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 3\
**Last updated:** [April 25, 2025, 9:06pm UTC](https://discourse.julialang.org/t/custom-dictionary-type-fieldless-keytype-fieldless-valtype/128405 "2025-04-25T21:06:21Z")

</div>

Suppose there are some mutable struct types with no fields, and with the default (fallback) equality and hashing methods. A value of such a type has its identity as its only quality. For example: mutable struct A end mu…

---

## [Performance of Dictionaries.jl vs Base.Dict](https://discourse.julialang.org/t/performance-of-dictionaries-jl-vs-base-dict/92073)

<div class="topic-metadata">

**Author:** [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Replies:** 31\
**Last updated:** [December 13, 2024, 6:31pm UTC](https://discourse.julialang.org/t/performance-of-dictionaries-jl-vs-base-dict/92073 "2024-12-13T18:31:31Z")

</div>

Lots of places; Dictionaries.jl’s packages are just much faster than Base Dicts to iterate over. There’s a reason most package designers use them rather than Dicts.

---

## [How do I sort a dictionary by its keys?](https://discourse.julialang.org/t/how-do-i-sort-a-dictionary-by-its-keys/37848)

<div class="topic-metadata">

**Author:** [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Replies:** 10\
**Last updated:** [July 28, 2024, 8:59am UTC](https://discourse.julialang.org/t/how-do-i-sort-a-dictionary-by-its-keys/37848 "2024-07-28T08:59:15Z")

</div>

I want to sort this by its keys: 5-element Dictionaries.HashDictionary{Int64,Any} 4 │ 0.2199244 2 │ 0.2000908 3 │ 0.19014 5 │ 0.2099752 1 │ 0.1798696

---

## [Comparing Dictionaries of Dictionaries](https://discourse.julialang.org/t/comparing-dictionaries-of-dictionaries/110323)

<div class="topic-metadata">

**Author:** [@brombo](https://discourse.julialang.org/u/brombo)\
**Replies:** 16\
**Last updated:** [February 17, 2024, 6:52pm UTC](https://discourse.julialang.org/t/comparing-dictionaries-of-dictionaries/110323 "2024-02-17T18:52:54Z")

</div>

I am trying to compare two dictionaries to see if they are equal. In the code the dictionaries are S1.sdops and S2.sdops function (==)(D1::Sdop,D2::Sdop)::Bool if string(D1.s) != string(D2.s) return false end keys1 …

---

## [Counting the number of appearance of Tuples in a Vector](https://discourse.julialang.org/t/counting-the-number-of-appearance-of-tuples-in-a-vector/108901)

<div class="topic-metadata">

**Author:** [@blociss](https://discourse.julialang.org/u/blociss)\
**Replies:** 8\
**Last updated:** [January 17, 2024, 7:13pm UTC](https://discourse.julialang.org/t/counting-the-number-of-appearance-of-tuples-in-a-vector/108901 "2024-01-17T19:13:48Z")

</div>

Let vec = \[(“A”, “B”), (“A”, “C”), (“A”, “D”), (“B”, “C”), (“B”, “D”)\] be a vector. I want to count the number of appearance of each element at each step in the for loop. function count\_occurrences(vec) vect = \[\] …

---

## [Assigning value from a matrix to a dictionary with key as pairs(i,j)](https://discourse.julialang.org/t/assigning-value-from-a-matrix-to-a-dictionary-with-key-as-pairs-i-j/98548)

<div class="topic-metadata">

**Author:** [@Gagan\_Meena](https://discourse.julialang.org/u/Gagan_Meena)\
**Replies:** 4\
**Last updated:** [May 10, 2023, 4:48am UTC](https://discourse.julialang.org/t/assigning-value-from-a-matrix-to-a-dictionary-with-key-as-pairs-i-j/98548 "2023-05-10T04:48:23Z")

</div>

Pd = Pd\_max.\*load\_rat Pdm = sum(Pd, dims=1) Pg\_Dict = Dict{Pair{Int16,Int16}, Float16}() Pd\_Dict = Dict{Int16, Float16}() for i =1:n\_bus for j =1:n\_scenarios key = Pair(i,j) Pd\_Dict\[j\] = Pdm\[j\] value = Pg\[i,j\] P…

---

## [How to efficiently save and read dictionaries in Julia?](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337)

<div class="topic-metadata">

**Author:** [@F\_A](https://discourse.julialang.org/u/F_A)\
**Replies:** 3\
**Last updated:** [May 4, 2023, 7:02pm UTC](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337 "2023-05-04T19:02:43Z")

</div>

Hi, I’d like to save a dictionary to a file with more than 12500 entries. I’ve read some suggestion here and here. But I was wondering whether these are the most efficient way to do so? Thanks a lot.

---

## [Alternatives to Dictionaries in Julia](https://discourse.julialang.org/t/alternatives-to-dictionaries-in-julia/94901)

<div class="topic-metadata">

**Author:** [@ivoytov](https://discourse.julialang.org/u/ivoytov)\
**Replies:** 10\
**Last updated:** [February 20, 2023, 3:59pm UTC](https://discourse.julialang.org/t/alternatives-to-dictionaries-in-julia/94901 "2023-02-20T15:59:53Z")

</div>

I’ve been slowly porting my Java and Python code to Julia and frequently come across statements like “dictionaries are less commonly used in Julia” 1 I catch myself using dictionaries all the time in Julia, as direct re…

---

## [Create graph from public Mastodon data](https://discourse.julialang.org/t/create-graph-from-public-mastodon-data/90637)

<div class="topic-metadata">

**Author:** [@mmeer](https://discourse.julialang.org/u/mmeer)\
**Replies:** 2\
**Last updated:** [February 8, 2023, 2:33pm UTC](https://discourse.julialang.org/t/create-graph-from-public-mastodon-data/90637 "2023-02-08T14:33:31Z")

</div>

Hi there, I have written a script to fetch an array of accounts that I follow on Mastodon. Each account is represented by a dictionary with KeySet for a Dict{String, Any} with 21 entries. Keys: "acct" "locked" "c…

---

## [Map data from one dictionary into another](https://discourse.julialang.org/t/map-data-from-one-dictionary-into-another/92890)

<div class="topic-metadata">

**Author:** [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Replies:** 5\
**Last updated:** [January 13, 2023, 8:30pm UTC](https://discourse.julialang.org/t/map-data-from-one-dictionary-into-another/92890 "2023-01-13T20:30:08Z")

</div>

I have data from two APIs in JSON format and parsing them into 2 dictionaries (d1, d2). I need to derive two additional fields FieldName(from d2), attrVal from d1() by mapping subAttrDefId present in d1(“attrValues”) wi…

---

## [Nested Dict can't figure out how to traverse the structure](https://discourse.julialang.org/t/nested-dict-cant-figure-out-how-to-traverse-the-structure/82704)

<div class="topic-metadata">

**Author:** [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Replies:** 4\
**Last updated:** [June 13, 2022, 9:07pm UTC](https://discourse.julialang.org/t/nested-dict-cant-figure-out-how-to-traverse-the-structure/82704 "2022-06-13T21:07:16Z")

</div>

I am trying to populate a dash table and think the issue is that I don’t know how to traverse a nested dict properly. I have a Dict data\_flow = Dict{String, Any}("AMZN" =\> Dict{String, Any}("hv10" =\> "45.99", "…

---

## [Is there a way I can identity Dict just like identity Vector?](https://discourse.julialang.org/t/is-there-a-way-i-can-identity-dict-just-like-identity-vector/81897)

<div class="topic-metadata">

**Author:** [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Replies:** 3\
**Last updated:** [May 30, 2022, 5:24am UTC](https://discourse.julialang.org/t/is-there-a-way-i-can-identity-dict-just-like-identity-vector/81897 "2022-05-30T05:24:43Z")

</div>

I often identity Vector: vec\_a=Any\[1,2,3\] 3-element Vector{Any}: 1 2 3 identity.(vec\_a) 3-element Vector{Int64}: 1 2 3 But when I have a Dict: dict\_a=Dict{S,Any}(:a=\>1,:b=\>2) Dict{Symbol, Any} with 2 entries: …

---

## [How does \`Base.ImmutableDict\` work internally?](https://discourse.julialang.org/t/how-does-base-immutabledict-work-internally/74117)

<div class="topic-metadata">

**Author:** [@wmanning-cra](https://discourse.julialang.org/u/wmanning-cra)\
**Replies:** 1\
**Last updated:** [January 6, 2022, 2:20am UTC](https://discourse.julialang.org/t/how-does-base-immutabledict-work-internally/74117 "2022-01-06T02:20:16Z")

</div>

I just discovered Base.ImmutableDict, and it appears to be a very strange type. I get the core concept of a linked list of key-value pairs. But the reference to the next node is of type Base.ImmutableDict{K, V}. How can …

---

## [Efficiently finding the frequency of patterns in DataFrame columns](https://discourse.julialang.org/t/efficiently-finding-the-frequency-of-patterns-in-dataframe-columns/73839)

<div class="topic-metadata">

**Author:** [@Matthew](https://discourse.julialang.org/u/Matthew)\
**Replies:** 12\
**Last updated:** [January 1, 2022, 9:27pm UTC](https://discourse.julialang.org/t/efficiently-finding-the-frequency-of-patterns-in-dataframe-columns/73839 "2022-01-01T21:27:58Z")

</div>

Hi all! I’m looking for help with what might be an easy task. Say we have two vectors; A = \[0,1\] and B = \[0,1,2\]. Matrix C contains every possible combination of A and B such that it has dimensions 6x2. Now consider a…

---

## [Understanding struct hashes](https://discourse.julialang.org/t/understanding-struct-hashes/73202)

<div class="topic-metadata">

**Author:** [@jerlich](https://discourse.julialang.org/u/jerlich)\
**Replies:** 13\
**Last updated:** [December 18, 2021, 6:45pm UTC](https://discourse.julialang.org/t/understanding-struct-hashes/73202 "2021-12-18T18:45:39Z")

</div>

When i change a dictionary the hash changes. julia\> d1 = Dict{Any,Any}() julia\> hash(d1) 0x172af099a2a3a421 julia\> d1\[:A\] = 13245 julia\> hash(d1) 0x9dee08cef4972aa5 If I make a struct with a dictionary the hash of th…

---

## [Dictionaries can't find keys](https://discourse.julialang.org/t/dictionaries-cant-find-keys/69488)

<div class="topic-metadata">

**Author:** [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Replies:** 34\
**Last updated:** [October 10, 2021, 8:56pm UTC](https://discourse.julialang.org/t/dictionaries-cant-find-keys/69488 "2021-10-10T20:56:40Z")

</div>

I have this dictionary starting\_balance=starting\_balance=Dict( # Starting Balance consists of a dictionary, containing debit and credit dictionaries, containing accounts as empty dictionaries. #accounts are organized…

---

## [What does Dict{T} mean?](https://discourse.julialang.org/t/what-does-dict-t-mean/69455)

<div class="topic-metadata">

**Author:** [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Replies:** 4\
**Last updated:** [October 8, 2021, 10:07pm UTC](https://discourse.julialang.org/t/what-does-dict-t-mean/69455 "2021-10-08T22:07:54Z")

</div>

Hi! Here is the tiny project I have in mind so that I get my hands a bit dirty. I would like to extend the functionality of StatsBase.countmap() so that is accepts the Dictionary type aside from the Dict inbuilt data ty…

---

## [\[ANN\] Dictionaries.jl - Improved productivity and performance of dictionaries in Julia](https://discourse.julialang.org/t/ann-dictionaries-jl-improved-productivity-and-performance-of-dictionaries-in-julia/32074)

<div class="topic-metadata">

**Author:** [@andyferris](https://discourse.julialang.org/u/andyferris)\
**Replies:** 22\
**Last updated:** [December 15, 2019, 3:30am UTC](https://discourse.julialang.org/t/ann-dictionaries-jl-improved-productivity-and-performance-of-dictionaries-in-julia/32074 "2019-12-15T03:30:11Z")

</div>

I am pleased to announce the recent release of Dictionaries.jl, which provides an alternative interface for dictionaries in Julia, for improved productivity and performance. You can install it with \]add Dictionaries at t…
