# Jinja accessing local dictionary with key as variable from loop

**URL:** <https://forum.ansible.com/t/jinja-accessing-local-dictionary-with-key-as-variable-from-loop/14844>\
**Category:** Ansible Project\
**Created:** [March 24, 2014, 6:35pm UTC](https://forum.ansible.com/t/jinja-accessing-local-dictionary-with-key-as-variable-from-loop/14844 "2014-03-24T18:35:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas.lehmann.priva](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@thomas.lehmann.priva](https://forum.ansible.com/u/thomas.lehmann.priva)\
**Post date:** [March 24, 2014, 6:35pm UTC](https://forum.ansible.com/t/jinja-accessing-local-dictionary-with-key-as-variable-from-loop/14844/1 "2014-03-24T18:35:14Z")

</div>

Hi,

the first line provides a dictionary of actors (names). The values are a list of movies.  
In a loop over a movie and there over each actor I want to know in how many movies  
an actor plays a role. I’m not able to access the dictionary …

… I tried actors[actor] as well as actors.get(actor) but

{% set actors = page.statistic.getActorsAsDictionary() %}  
…  
{{ actors.get(actor)|length }} =\> yells about NoneType  
{{ actors[actor]|length }} =\> always 0

I tried it this way:  
{% set actors = {“Dennis Quaid”: [1]} %}  
{{ actors[actor]|length }} =\> always 0

It DOES work for:  
{% set actors = {“Dennis Quaid”: [1234]} %}  
{{ actors[“Dennis Quaid”]|length }} =\> is “1”

What did I wrong?

Regards,  
Thomas
