# Accessing A Dictionary Item That is an Array

**URL:** <https://discuss.python.org/t/accessing-a-dictionary-item-that-is-an-array/4125>\
**Category:** Python Help\
**Created:** [May 7, 2020, 2:24pm UTC](https://discuss.python.org/t/accessing-a-dictionary-item-that-is-an-array/4125 "2020-05-07T14:24:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gw1500se1](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/gw1500se1/32/2155_2.png) [@gw1500se1](https://discuss.python.org/u/gw1500se1)\
**Post date:** [May 7, 2020, 2:24pm UTC](https://discuss.python.org/t/accessing-a-dictionary-item-that-is-an-array/4125/1 "2020-05-07T14:24:55Z")

</div>

I have the following dictionary defined:

menu={  
‘main’:‘Main’,‘index’:0,  
‘items’:[‘Temp Control’,‘Blowers’,‘System Info’,‘Network’]  
}

I cannot figure out the correct syntax for accessing the nth element of ‘items’.

print(menu[‘main’][‘items’[0]])

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [May 7, 2020, 9:02pm UTC](https://discuss.python.org/t/accessing-a-dictionary-item-that-is-an-array/4125/2 "2020-05-07T21:02:53Z")

</div>

Gw1500se1 defined a dict:

```
menu={
      'main':'Main',
      'index':0,
      'items':['Temp Control','Blowers','System Info','Network']
      }

```

then tried this:

```
print(menu['main']['items'[0]])

```

Break it down step-by step:

- `menu['main']` returns the string ‘Main’;

- `'items'[0]` returns the character `'i'`;

- so the third step becomes `'Main'['i']` which fails.

Instead, you need:

- `menu['items']` to return the list;

- followed by indexing the n-th element of the list.

Putting them together with the call to `print` gives us:

```
print(menu['items'][0])

```

which prints “Temp Control”.

---

<div class="post-metadata">

**Author:** ![gw1500se1](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/gw1500se1/32/2155_2.png) [@gw1500se1](https://discuss.python.org/u/gw1500se1)\
**Post date:** [May 8, 2020, 1:31pm UTC](https://discuss.python.org/t/accessing-a-dictionary-item-that-is-an-array/4125/3 "2020-05-08T13:31:15Z")

</div>

Thanks for the reply. I see now. I was thinking one level too deep. I was treating items as if it were an element of main rather than menu.
