# How to connect two dictionary together?

**URL:** https://discourse.julialang.org/t/how-to-connect-two-dictionary-together/86938
**Category:** General Usage
**Tags:** question, tuple, dictionary
**Created:** [September 8, 2022, 12:37pm UTC](https://discourse.julialang.org/t/how-to-connect-two-dictionary-together/86938 "2022-09-08T12:37:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![frank20000](https://avatars.discourse-cdn.com/v4/letter/f/13edae/32.png) [@frank20000](https://discourse.julialang.org/u/frank20000)
#### Post date: [September 8, 2022, 12:37pm UTC](https://discourse.julialang.org/t/how-to-connect-two-dictionary-together/86938/1 "2022-09-08T12:37:34Z")

</div>

Hi there,

Do you know of any easy way of connecting two or more tuples together? A simple example that explains one of the thing I need is this situation:

I have a dictionary that maps a set of pairs to a value `(1,2) => 10 ` or `(1,8) => 7`. I have another vector of triples that the first two elements are all intersect with previous pairs; like `(1,2,1) (1,2,2) (1,8,1)` . So is there a simple method that I can map the values of first pairs to triples regardless of their third component? The issue is that the length of pairs are not the same as the length of triples. In some instances pairs are greater and in others not. But the way I have to think on mapping would be similar, yes?

for instance

```julia
# Pair_dict: Dict{Tuple{Int64, Int64}, Float64} 
Prices = Dict(all_pairs .=> price) # where all_pairs and price are number 
(1,2) => 10
(1,8) => 7
(2,2) => 9
(2,5) => 8
(2,7) =>4
(3,1) => 9
(3,6) =>5

```

Then triples might be

```julia
# the third component are a vector of costumers [1,2,7] for example
Orders = [(1,2,1) , (1,2,2), (1,8,1), (1,8,2), (2,7,1), (2,5,1), (3,1,1), (3,1,7)]  

```

how to say `(1,2,1) => 10` , `(1,2,2) => 10` and so `(1,2,anything) => 10`

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [September 8, 2022, 12:49pm UTC](https://discourse.julialang.org/t/how-to-connect-two-dictionary-together/86938/2 "2022-09-08T12:49:40Z")

</div>

How about this?

```julia
Prices = Dict([
(1,2) => 10
(1,8) => 7
(2,2) => 9
(2,5) => 8
(2,7) =>4
(3,1) => 9
(3,6) => 5
])

Orders = [(1,2,1) , (1,2,2), (1,8,1), (1,8,2), (2,7,1), (2,5,1), (3,1,1), (3,1,7)]

Price_Orders = Dict([(a,b,c) => Prices[(a,b)] for (a,b,c) in Orders])

```

---

<div class="post-metadata">

### Author: ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)
#### Post date: [September 8, 2022, 1:29pm UTC](https://discourse.julialang.org/t/how-to-connect-two-dictionary-together/86938/3 "2022-09-08T13:29:30Z")

</div>

Following @jd-foster’s answer: if the number of orders (`length(Orders)`) is large, then turning the array comprehension into a generator could bring a reasonable speed up.

```julia
Price_Orders = Dict([(a,b,c) => Prices[(a,b)] for (a,b,c) in Orders]) #before
Price_Orders = Dict((a,b,c) => Prices[(a,b)] for (a,b,c) in Orders) #after

```
