how to get values from dict in template with for loop ?

I have two dict file like

teams.yml

{
“teams”: [{“gid”: 10125,“location”: [“hq”],“name”: “aa”,“users”: [“chenhu”,“chouf”]},
{“gid”: 10126,“location”: [“hq”],“name”: “ac”,“users”: [“guoj”,“yangc”]} ]

}

users.yml
{

“users”: [{“name”: “changc”,“uid”: 20000},
{“name”: “changb”,“uid”: 20001} ]
}

I want to generate a file using template , so I start with two seperate for loop for test
{% for i in users %}
{{ i.uid }} {{ i.name }}
{% endfor %}

{% for j in teams %}
{{ j.users }} {{ j.name }}
{% endfor %}

and ansible run with errors
AnsibleUndefinedVariable: ‘dict object’ has no attribute ‘users’

but teams dictonary did have users attr , why ansible can not get the value ??

so if I want to create a for loop in jinja2 template the condition is
when user’s name show in teams then write down user’s name and teams name
how do I do it ?
{% for i in users %}
{for j in teams %}
{if i.name in j.users %}
{{ i.name }}_{{ j.name }}
{% endif %}
{% endfor %}
{% endfor %}

that’s my first thought , but I have no idea how to do now …
any suggestions ??