# \#dictionary

**URL:** https://discourse.julialang.org/tag/dictionary/156.md

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

---

## [\`get()\` returns default value instead of value matching to valid key when default value is an \`error()\`](https://discourse.julialang.org/t/get-returns-default-value-instead-of-value-matching-to-valid-key-when-default-value-is-an-error/137670)

<div class="topic-metadata">

**Author:** [@jlawrie](https://discourse.julialang.org/u/jlawrie)\
**Replies:** 10\
**Last updated:** [June 19, 2026, 12:26pm UTC](https://discourse.julialang.org/t/get-returns-default-value-instead-of-value-matching-to-valid-key-when-default-value-is-an-error/137670 "2026-06-19T12:26:09Z")

</div>

Hello everyone! Looking at the MWE below: It appears error/throw are run before get is finished, causing get to be interrupted and the default value to be returned, rather than the value which matches the valid key as …

---

## [\[ANN\] SmallCollections.jl: fast small vectors, sets and dictionaries](https://discourse.julialang.org/t/ann-smallcollections-jl-fast-small-vectors-sets-and-dictionaries/128787)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 9\
**Last updated:** [November 7, 2025, 1:01pm UTC](https://discourse.julialang.org/t/ann-smallcollections-jl-fast-small-vectors-sets-and-dictionaries/128787 "2025-11-07T13:01:55Z")

</div>

The standard container types in Julia (Vector, Set, Dict) can hold an arbitrary number of elements. If the size is known in advance, one can use dedicated types like SVector or MVector from StaticArrays.jl that are much …

---

## [Multi-threaded processing of a Dict](https://discourse.julialang.org/t/multi-threaded-processing-of-a-dict/131996)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 8\
**Last updated:** [September 1, 2025, 2:09pm UTC](https://discourse.julialang.org/t/multi-threaded-processing-of-a-dict/131996 "2025-09-01T14:09:08Z")

</div>

I have a function that iterates over all key-value pairs, does a computation based on the key and the value and then updates the value at that key. Due to the fact that in each iteration I only update the value and don’t…

---

## [Converting Dict to DataFrames](https://discourse.julialang.org/t/converting-dict-to-dataframes/131248)

<div class="topic-metadata">

**Author:** [@Snowy](https://discourse.julialang.org/u/Snowy)\
**Replies:** 4\
**Last updated:** [July 31, 2025, 4:42pm UTC](https://discourse.julialang.org/t/converting-dict-to-dataframes/131248 "2025-07-31T16:42:23Z")

</div>

Hi all, I’m sure this is pretty simple but it’s tripping me up. Say I have a dictionary as such: using DataFrames using Dates Dates\_to\_remember = Dict(:Birthday=\> Set(\[ Date("2021-01-15"), Date("1991-08-30"),…

---

## [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…

---

## [How To Quickly Iterate over a Collection of Dictionaries?](https://discourse.julialang.org/t/how-to-quickly-iterate-over-a-collection-of-dictionaries/125588)

<div class="topic-metadata">

**Author:** [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Replies:** 2\
**Last updated:** [February 5, 2025, 9:35pm UTC](https://discourse.julialang.org/t/how-to-quickly-iterate-over-a-collection-of-dictionaries/125588 "2025-02-05T21:35:51Z")

</div>

Hi folks! :wave: I have a rather large JSON file. The good news is that the JSON is not heavily nested (only 2 levels deep). What is the most efficient way to filter relevant parts of a JSON structure I need based on a …

---

## [How to initialize a \`Dict\` with \`#undef\` content?](https://discourse.julialang.org/t/how-to-initialize-a-dict-with-undef-content/125154)

<div class="topic-metadata">

**Author:** [@Shayan](https://discourse.julialang.org/u/Shayan)\
**Replies:** 6\
**Last updated:** [January 26, 2025, 1:10pm UTC](https://discourse.julialang.org/t/how-to-initialize-a-dict-with-undef-content/125154 "2025-01-26T13:10:28Z")

</div>

I want to initialize a Dict comprised of some #undef values. How can I do this? I tried Dict{String, Float64}(undef, 3) but it throws the following error: ERROR: MethodError: no method matching Dict{String, Float64}(::…

---

## [Dict with integer keys and fastest insertion?](https://discourse.julialang.org/t/dict-with-integer-keys-and-fastest-insertion/125171)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 8\
**Last updated:** [January 25, 2025, 1:28pm UTC](https://discourse.julialang.org/t/dict-with-integer-keys-and-fastest-insertion/125171 "2025-01-25T13:28:35Z")

</div>

What are the best options for a dict/map with integer keys and the fastest insert/update? For background, I wish to aggregate those position-weight pairs (p,w) where the position is the same, I’m tinkering with the idea …

---

## [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.

---

## [Should Dict avoid GC allocations for isbits key/value types?](https://discourse.julialang.org/t/should-dict-avoid-gc-allocations-for-isbits-key-value-types/123613)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 3\
**Last updated:** [December 10, 2024, 1:16am UTC](https://discourse.julialang.org/t/should-dict-avoid-gc-allocations-for-isbits-key-value-types/123613 "2024-12-10T01:16:36Z")

</div>

Resizing arrays, when elements have primitive types or more generally isbits types, does not trigger any GC, as this is handled by the C runtime. Dictionaries are also allocation-free during most operations, except durin…

---

## [In what case \`x===y\` and \`objectid(x) == objectid(y)\` are not interchangable?](https://discourse.julialang.org/t/in-what-case-x-y-and-objectid-x-objectid-y-are-not-interchangable/123265)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 3\
**Last updated:** [November 29, 2024, 11:42pm UTC](https://discourse.julialang.org/t/in-what-case-x-y-and-objectid-x-objectid-y-are-not-interchangable/123265 "2024-11-29T23:42:25Z")

</div>

I was reading the official documentation and found the following statement about objectid: If x === y then objectid(x) == objectid(y) , and usually when x !== y , objectid(x) != objectid(y) . It seems that there are …

---

## [\`IdDict{UInt64, Float64}\` is much slower than \`Dict{UInt64, Float64}\` for retrieving values](https://discourse.julialang.org/t/iddict-uint64-float64-is-much-slower-than-dict-uint64-float64-for-retrieving-values/123144)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 2\
**Last updated:** [November 27, 2024, 8:36pm UTC](https://discourse.julialang.org/t/iddict-uint64-float64-is-much-slower-than-dict-uint64-float64-for-retrieving-values/123144 "2024-11-27T20:36:16Z")

</div>

MWE: julia\> k = rand(UInt, 5000); julia\> v = rand(Float64, 5000); julia\> using Random julia\> ks = shuffle(k); julia\> d1 = Dict(k .=\> v); julia\> d2 = IdDict(k .=\> v); julia\> using BenchmarkTools julia\> @benchmark …

---

## [Compare data from two dataframes](https://discourse.julialang.org/t/compare-data-from-two-dataframes/118254)

<div class="topic-metadata">

**Author:** [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Replies:** 3\
**Last updated:** [August 17, 2024, 1:57pm UTC](https://discourse.julialang.org/t/compare-data-from-two-dataframes/118254 "2024-08-17T13:57:45Z")

</div>

I have two dataframes as shown below and I need to create csv file or json output like shown below. I need to get dominant row for each product for each date from two dataframes then compare them to generate below outpu…

---

## [Why does \`show\` for arrays and dictionaries ignore \`:compact\`?](https://discourse.julialang.org/t/why-does-show-for-arrays-and-dictionaries-ignore-compact/118159)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 6\
**Last updated:** [August 14, 2024, 5:43am UTC](https://discourse.julialang.org/t/why-does-show-for-arrays-and-dictionaries-ignore-compact/118159 "2024-08-14T05:43:30Z")

</div>

The documentation for IOContext says :compact output should not contain line breaks However, this is ignored by arrays and dictionaries: julia\> show(IOContext(stdout, :compact =\> true), MIME"text/plain"(), \[1, 2\]) 2…

---

## [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

---

## [How to create a struct from a dict](https://discourse.julialang.org/t/how-to-create-a-struct-from-a-dict/117550)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 7\
**Last updated:** [July 27, 2024, 9:32pm UTC](https://discourse.julialang.org/t/how-to-create-a-struct-from-a-dict/117550 "2024-07-27T21:32:08Z")

</div>

I have a Dict from parsing a JSON message, and want to convert it into a struct. This works: using StaticArrays const MyFloat = Float64 sys\_state\_dict = Dict(:time =\> 0, :t\_sim =\> 0, :sys\_state =\> 0,…

---

## [Parallel accumulation over large dictionary](https://discourse.julialang.org/t/parallel-accumulation-over-large-dictionary/116316)

<div class="topic-metadata">

**Author:** [@OHL](https://discourse.julialang.org/u/OHL)\
**Replies:** 2\
**Last updated:** [June 27, 2024, 7:32pm UTC](https://discourse.julialang.org/t/parallel-accumulation-over-large-dictionary/116316 "2024-06-27T19:32:43Z")

</div>

I have a large Dict D and a function f that takes as input a pair of dictionary entries and outputs a float. I would like to compute f for all pairs in D and sum the results. f is also symmetric, f(a,b) = f(b,a), so I on…

---

## [Declare tuple type of arbitrary length](https://discourse.julialang.org/t/declare-tuple-type-of-arbitrary-length/115199)

<div class="topic-metadata">

**Author:** [@bsuwal](https://discourse.julialang.org/u/bsuwal)\
**Replies:** 0\
**Last updated:** [June 4, 2024, 9:41pm UTC](https://discourse.julialang.org/t/declare-tuple-type-of-arbitrary-length/115199 "2024-06-04T21:41:45Z")

</div>

Is there any way I can declare a type for my dictionary with a tuple of the same element type but of arbitrary length? For example I can currently do this: d = Dict{Tuple{Int, Int}, String}() d\[(1, 2)\] = "a" and get a…

---

## [Merge Dictionaries with values of type Vector](https://discourse.julialang.org/t/merge-dictionaries-with-values-of-type-vector/114703)

<div class="topic-metadata">

**Author:** [@sardinecan](https://discourse.julialang.org/u/sardinecan)\
**Replies:** 3\
**Last updated:** [May 25, 2024, 6:42am UTC](https://discourse.julialang.org/t/merge-dictionaries-with-values-of-type-vector/114703 "2024-05-25T06:42:10Z")

</div>

Hi everyone, I try to merge two dictionaries and one of them contains a vector value. Unfortunately, all the merging methods used return the same error: body = Dict( :scope =\> "deposited" ) # an optional paramete…

---

## [Replacing components with indices](https://discourse.julialang.org/t/replacing-components-with-indices/113412)

<div class="topic-metadata">

**Author:** [@KeepLearning](https://discourse.julialang.org/u/KeepLearning)\
**Replies:** 12\
**Last updated:** [April 25, 2024, 4:00pm UTC](https://discourse.julialang.org/t/replacing-components-with-indices/113412 "2024-04-25T16:00:55Z")

</div>

I am wondering if the following can be done in a better way (without for loop, perhaps): given a vector and a vector of vectors, e.g. v = \[1, 2, 3, 3, 4, 4, 5\] u = \[\[1,2\], \[3, 5\], \[4\]\] I like to get \[1, 1, 2, 2, 3, 3,…

---

## [Basic question about type invariance](https://discourse.julialang.org/t/basic-question-about-type-invariance/112674)

<div class="topic-metadata">

**Author:** [@Jesse1](https://discourse.julialang.org/u/Jesse1)\
**Replies:** 4\
**Last updated:** [April 8, 2024, 1:12pm UTC](https://discourse.julialang.org/t/basic-question-about-type-invariance/112674 "2024-04-08T13:12:09Z")

</div>

Hi there, I am getting unexpected behaviour with the DataType Dict when trying to specify subtypes. Specifically, I want a function to be able to accept a Dict where the keys are strings and the entries are tuples conta…

---

## [Have an strange error creating optimization subproblems on Julia](https://discourse.julialang.org/t/have-an-strange-error-creating-optimization-subproblems-on-julia/112692)

<div class="topic-metadata">

**Author:** [@benjamin.nunez](https://discourse.julialang.org/u/benjamin.nunez)\
**Replies:** 5\
**Last updated:** [April 9, 2024, 5:27am UTC](https://discourse.julialang.org/t/have-an-strange-error-creating-optimization-subproblems-on-julia/112692 "2024-04-09T05:27:53Z")

</div>

Hello! I’m experiencing a rather strange problem in Julia when creating optimization subproblems. Basically I have a function called “build\_subproblem(s)” which depends on a scenario “s” and formulates an optimization p…

---

## [HDF5 high-level wrapper for nested Dicts](https://discourse.julialang.org/t/hdf5-high-level-wrapper-for-nested-dicts/111588)

<div class="topic-metadata">

**Author:** [@baptnz](https://discourse.julialang.org/u/baptnz)\
**Replies:** 3\
**Last updated:** [March 14, 2024, 4:58am UTC](https://discourse.julialang.org/t/hdf5-high-level-wrapper-for-nested-dicts/111588 "2024-03-14T04:58:01Z")

</div>

I’m storing some data in hdf5 format to use in a multilanguage environment (others will use Python, R, C, etc. to access those files). I’ve implemented the export using HDF5.jl without much trouble, but it’s not very wel…

---

## [Reorder dictionary keys](https://discourse.julialang.org/t/reorder-dictionary-keys/111547)

<div class="topic-metadata">

**Author:** [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Replies:** 8\
**Last updated:** [March 13, 2024, 6:58am UTC](https://discourse.julialang.org/t/reorder-dictionary-keys/111547 "2024-03-13T06:58:43Z")

</div>

I have dictionary in below format and would like to check if we have any existing methos that can reorder dictionary if we provide the array with the key names in desired order? I would like to see my final dictionary i…

---

## [\`mergewith\` issue with \`Unitful\`](https://discourse.julialang.org/t/mergewith-issue-with-unitful/111087)

<div class="topic-metadata">

**Author:** [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Replies:** 9\
**Last updated:** [March 3, 2024, 11:28pm UTC](https://discourse.julialang.org/t/mergewith-issue-with-unitful/111087 "2024-03-03T23:28:07Z")

</div>

I’ve been using mergewith(+, …) with Dicts containing Unitful values, and it worked great for a while … until it suddenly didn’t. And slight reorganization of the arguments made it work again, so I’m not quite sure what’…

---

## [Updating values in a dictionary with a minimum of lookups](https://discourse.julialang.org/t/updating-values-in-a-dictionary-with-a-minimum-of-lookups/110544)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 2\
**Last updated:** [February 21, 2024, 10:04pm UTC](https://discourse.julialang.org/t/updating-values-in-a-dictionary-with-a-minimum-of-lookups/110544 "2024-02-21T22:04:34Z")

</div>

I’m trying to do random-access updates to Int values in a dictionary in the most efficient way possible, but it seems hard to avoid extra hash calls. Here’s the naive approach: struct A x::Int end function Base.has…

---

## [Dictionary lookup errors when the struct contains empty vectors](https://discourse.julialang.org/t/dictionary-lookup-errors-when-the-struct-contains-empty-vectors/109965)

<div class="topic-metadata">

**Author:** [@kangboli](https://discourse.julialang.org/u/kangboli)\
**Replies:** 6\
**Last updated:** [February 9, 2024, 10:31pm UTC](https://discourse.julialang.org/t/dictionary-lookup-errors-when-the-struct-contains-empty-vectors/109965 "2024-02-09T22:31:49Z")

</div>

I’m running into a problem with Dict and I think it could be a bug? Julia’s documentation says that the implementation of Dict uses hash as the hashing function for the key, and isequal to determine equality, but the fol…

---

## [Select a dictionary in a vector based on a specific entry value](https://discourse.julialang.org/t/select-a-dictionary-in-a-vector-based-on-a-specific-entry-value/109876)

<div class="topic-metadata">

**Author:** [@sardinecan](https://discourse.julialang.org/u/sardinecan)\
**Replies:** 4\
**Last updated:** [February 9, 2024, 2:48pm UTC](https://discourse.julialang.org/t/select-a-dictionary-in-a-vector-based-on-a-specific-entry-value/109876 "2024-02-09T14:48:54Z")

</div>

Hi everyone, I’m looking for an easy way to filter/select dict in vector based on the value of one of the key. In the example below, I need to find the title of a data, given by the first Dict of the vector (but it is …

---

## [Use Dict to store tree with uninitialized tree nodes](https://discourse.julialang.org/t/use-dict-to-store-tree-with-uninitialized-tree-nodes/109895)

<div class="topic-metadata">

**Author:** [@Julia2001](https://discourse.julialang.org/u/Julia2001)\
**Replies:** 4\
**Last updated:** [February 8, 2024, 8:03pm UTC](https://discourse.julialang.org/t/use-dict-to-store-tree-with-uninitialized-tree-nodes/109895 "2024-02-08T20:03:02Z")

</div>

I would like to use a Dict with string keys to store a tree. The relations between nodes evolve over time. So they have to be left uninitialized for the most part during initial construction. I read about inner and oute…

[Next page](https://discourse.julialang.org/tag/dictionary/156.md?match_all_tags=true&page=1&tags%5B%5D=dictionary)
