# Dictionaries and such

**URL:** <https://discourse.julialang.org/t/dictionaries-and-such/130443>\
**Category:** General Usage\
**Created:** [July 3, 2025, 9:40am UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443 "2025-07-03T09:40:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![skypuppy](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skypuppy](https://discourse.julialang.org/u/skypuppy)\
**Post date:** [July 3, 2025, 9:40am UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/1 "2025-07-03T09:40:29Z")

</div>

I hated using dictionaries in Python, mostly because they in-memory only. I guess I am so accustomed to relational DBMS’s that I just can’t think any other way. So, truly, are dictionaries that useful in Julia? Are they even used anywhere except for the most trivial of tasks? Not trying to rain on anyone’s parade, trying to figure out how much study I should to attach to (re)learning them again. (Not a big fan of Python.) 🙂

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [July 3, 2025, 11:28am UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/2 "2025-07-03T11:28:50Z")

</div>

Well they are a tool at your disposal. If you don’t like them, then don’t use them 🙂  
Personally, I have barely used them. I think this is because they are less convenient to use in Julia than in Python, so I tend reach for other solutions.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [July 3, 2025, 11:30am UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/3 "2025-07-03T11:30:20Z")

</div>

Dictionaries are not that great for large or performance-critical data, but outside of that they are enormously useful, and used, for a large variety of tasks.

---

<div class="post-metadata">

**Author:** ![Salmon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/salmon/32/22968_2.png) [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Post date:** [July 3, 2025, 12:46pm UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/4 "2025-07-03T12:46:00Z")

</div>

I personally found dictionaries and Sets (which are just special dicts) to be immensely useful for some tasks which require bookkeping and frequent ` if i in array` kind of tasks.

Some of these problems are quite possibly much slower with standard arrays. In any case Dicts are very natural for them.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [July 3, 2025, 12:48pm UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/5 "2025-07-03T12:48:44Z")

</div>

why do you say this? `Dict` should be pretty performant across the general-purpose use case it is intended for. of course with more information about the specific problem at hand, often one can tailor a data structure for more performance (on that specific problem)

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [July 3, 2025, 1:12pm UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/6 "2025-07-03T13:12:45Z")

</div>

Of course they are fine for use cases they are intended for but they won’t help you when you want memory locality or SIMD optimizations.

But yes, if you ever need to repeatedly check if an element is in a large collection, place the collection in a `Set` and not in an `Array` (well, unless you can organize it as a lookup in a `BitVector`).

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [July 3, 2025, 3:36pm UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/7 "2025-07-03T15:36:16Z")

</div>

There are tasks for which dictionaries are the most suitable, such as counting word frequencies.

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [July 3, 2025, 7:23pm UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/8 "2025-07-03T19:23:14Z")

</div>

> [@GunnarFarneback](#):
>
> won’t help you when you want memory locality or SIMD optimizations

Dictionaries.jl can do a lot of operations with memory locality 🙂

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 3, 2025, 9:09pm UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/9 "2025-07-03T21:09:19Z")

</div>

Dictionaries are a basic abstract data type, and in-memory hash table implementations for O(1) indexing are fairly widespread and similar across many languages, including application e.g. memoization, dynamic fields. A couple practical differences between Python and Julia is that Julia has a wider variety of implementations used in practice, and they have type parameters for the keys and values.

A dictionary is too different from a relational database to be worth comparing, conceptually or in usual implementations. A dataframe/table would get closer (and could use a dictionary as a component), but still not close. I think you’re right that Python, or mostly teaching materials using it, exaggerate how useful dictionaries are alone because tutorials tend to overuse base features to avoid the learning curve of properly installing useful libraries. Implementing a database with `dict` and `list` outside of a toy example is as miserable as doing number crunching with `list` comprehensions instead of `numpy.ndarray`.

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [July 3, 2025, 9:12pm UTC](https://discourse.julialang.org/t/dictionaries-and-such/130443/10 "2025-07-03T21:12:45Z")

</div>

I think nothing prevents you from implementing your own struct that derives `AbstractDict`, you can even implement your file based one or even DB based one.
