# How to access Dictionary keys with Variable

**URL:** https://discourse.julialang.org/t/how-to-access-dictionary-keys-with-variable/17543
**Category:** General Usage
**Tags:** question
**Created:** [November 15, 2018, 2:32am UTC](https://discourse.julialang.org/t/how-to-access-dictionary-keys-with-variable/17543 "2018-11-15T02:32:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Rama](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rama/32/6011_2.png) [@Rama](https://discourse.julialang.org/u/Rama)
#### Post date: [November 15, 2018, 2:32am UTC](https://discourse.julialang.org/t/how-to-access-dictionary-keys-with-variable/17543/1 "2018-11-15T02:32:26Z")

</div>

Create a Dictionary of Maps

maps = Dict(:Arad =\> Dict(:Zerinda =\> 75,:Sibiu =\> 140,:Timisora =\> 118))

Access Arad key works with the below code

maps[:Arad]

Access nested key works with the below code

maps[:Arad][:Sibiu]

Access key with getindex method work with the below code

getindex(maps,:Arad)

Access nested key with getindex works with the below code

getindex(getindex(maps,:Arad),:Sibiu)

Assign a variable

startpos = “Arad”

Here is my issue. How can i get key and nested key value using the variable ? few example I have issues.

getindex(maps,startpos)

maps.[startpos]

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 15, 2018, 2:35am UTC](https://discourse.julialang.org/t/how-to-access-dictionary-keys-with-variable/17543/2 "2018-11-15T02:35:57Z")

</div>

Please read [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) and update your post.

Use `startpos = :Arad` (which is the same you used when you used the key directly)

---

<div class="post-metadata">

### Author: ![Rama](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rama/32/6011_2.png) [@Rama](https://discourse.julialang.org/u/Rama)
#### Post date: [November 15, 2018, 2:51am UTC](https://discourse.julialang.org/t/how-to-access-dictionary-keys-with-variable/17543/3 "2018-11-15T02:51:10Z")

</div>

Thanks it worked. Appreciate for your quick response.
