# Invertable Dict structure?

**URL:** https://discourse.julialang.org/t/invertable-dict-structure/7225
**Category:** General Usage
**Created:** [November 21, 2017, 6:25pm UTC](https://discourse.julialang.org/t/invertable-dict-structure/7225 "2017-11-21T18:25:41Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [November 21, 2017, 6:25pm UTC](https://discourse.julialang.org/t/invertable-dict-structure/7225/1 "2017-11-21T18:25:41Z")

</div>

Hello all. I was wondering if there is a “standard” implementation somewhere of an invertable lookup-table structure (i.e. a pair of `Dict`s, each the inverse of the other). Obviously this is trivial to implement using `Dict`, but I was wondering if there is a “standard” way of doing it. Thanks.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 21, 2017, 6:48pm UTC](https://discourse.julialang.org/t/invertable-dict-structure/7225/2 "2017-11-21T18:48:06Z")

</div>

What you want is called a [bidirectional map](https://en.wikipedia.org/wiki/Bidirectional_map). I’m not aware of any Julia package for this, and google doesn’t turn up anything…

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [November 21, 2017, 7:08pm UTC](https://discourse.julialang.org/t/invertable-dict-structure/7225/3 "2017-11-21T19:08:16Z")

</div>

Hm, perhaps a PR to [DataStructures](https://github.com/JuliaCollections/DataStructures.jl) would be welcome? I’m not personally aware whether there are any performance tricks involved in implementing this. We’d have to agree on the names for the `inverseget` methods. I suppose the reason this does not yet exist is because it is so trivial to do with two `Dict`s.

I think I would call it `BiDict`.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [November 21, 2017, 7:15pm UTC](https://discourse.julialang.org/t/invertable-dict-structure/7225/4 "2017-11-21T19:15:27Z")

</div>

I for one would use this as well. I sometimes need to use the value of a Dict as a key (as well as the key as a key).

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [November 21, 2017, 7:20pm UTC](https://discourse.julialang.org/t/invertable-dict-structure/7225/5 "2017-11-21T19:20:07Z")

</div>

To be honest, when I use this I feel “dirty”; as if the only reason I am doing it is because my code is poorly designed. But I think that is just my imagination, because it definitely seems unavoidable in some circumstances.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [November 21, 2017, 9:34pm UTC](https://discourse.julialang.org/t/invertable-dict-structure/7225/6 "2017-11-21T21:34:34Z")

</div>

Bah! Humbug!

I’ve used DataStructure stuff to realize I didn’t need them, to finally understand I did, to see the light that I don’t. But then I did.
