# Dictionary

**URL:** https://discourse.julialang.org/t/dictionary/46711
**Category:** General Usage
**Tags:** dictionary
**Created:** [September 16, 2020, 3:02pm UTC](https://discourse.julialang.org/t/dictionary/46711 "2020-09-16T15:02:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mmyousefies](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mmyousefies](https://discourse.julialang.org/u/mmyousefies)
#### Post date: [September 16, 2020, 3:02pm UTC](https://discourse.julialang.org/t/dictionary/46711/1 "2020-09-16T15:02:24Z")

</div>

hello, I’m new to Julia, and here’s my problem:  
using RDatasets, I wanted to make a dictionary of the first 2columns of the “iris” data frame; here’s how I did it:

> using RDataets  
> IRIS = dataset(“datasets”,“iris”)  
> j = Dict()  
> for i in 1:length(IRIS[!,1])  
> j[IRIS[i,1]]=IRIS[i,2]  
> end  
> but given that number of the entries must be 150 (there are150 rows in “iris” dataset), the dicitonary has only 35 entries:  
> julia\> j  
> Dict{Any,Any} with 35 entries:  
> 5.5 =\> 2.6  
> 4.3 =\> 3.0  
> 6.5 =\> 3.0  
> 7.7 =\> 3.0  
> 4.5 =\> 2.3  
> 5.9 =\> 3.0  
> 7.1 =\> 3.0  
> 7.0 =\> 3.2  
> 7.4 =\> 2.8  
> 4.4 =\> 3.2  
> 5.7 =\> 2.5  
> 6.7 =\> 3.0  
> 6.2 =\> 3.4  
> 4.7 =\> 3.2  
> 6.4 =\> 3.1  
> 6.6 =\> 3.0  
> 6.0 =\> 3.0  
> 4.6 =\> 3.2  
> 6.1 =\> 2.6  
> 6.8 =\> 3.2  
> 6.3 =\> 2.5  
> 5.8 =\> 2.7  
> 6.9 =\> 3.1  
> 5.1 =\> 2.5  
> 5.2 =\> 2.7  
> 5.3 =\> 3.7  
> 7.6 =\> 3.0  
> 4.8 =\> 3.0  
> 5.0 =\> 2.3  
> 5.6 =\> 2.8  
> 7.3 =\> 2.9  
> 4.9 =\> 2.5  
> 7.2 =\> 3.0  
> 5.4 =\> 3.0  
> 7.9 =\> 3.8

what did i do wrong? thank you.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [September 16, 2020, 3:11pm UTC](https://discourse.julialang.org/t/dictionary/46711/2 "2020-09-16T15:11:28Z")

</div>

The first column of `IRIS` only has 35 unique values. Consequently, you are overwriting values in the `Dict` as you assign them.

See the following

```julia
julia> d = Dict();

julia> d["a"] = 1
1

julia> d["a"] = 2
2

julia> d
Dict{Any,Any} with 1 entry:
  "a" => 2

```

---

<div class="post-metadata">

### Author: ![mmyousefies](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mmyousefies](https://discourse.julialang.org/u/mmyousefies)
#### Post date: [September 16, 2020, 4:23pm UTC](https://discourse.julialang.org/t/dictionary/46711/3 "2020-09-16T16:23:11Z")

</div>

wow! thankyou! I appreciate it.
