0

I have a list like account_id_list = [1,2,3,4,5,6,7]

I have a dictionary like tag_dict = [1:{"a"= "b", "y"= "z"}, 2:{"a"= "b", "y"= "z"}, 3:{"a"= "b", "y"= "z"}]

I want to perform an operation in jinja2 such that i should be able to do a for loop on account_id_list and using the value 3 as a reference i should be able to fetch the key i.e 3 in tag_dict and fetch its values.

I am pretty new to jinga and i tried to use a for loop inside a for loop but it's running for a long time and i want to know if there is a easy way of doing it.

Yash Kamdar
  • 131
  • 6

1 Answers1

1

Your tag_dict looks malformed. Did you mean this?

tag_dict = {1:{"a":"b","y":"z"},2:{"a":"b","y":"z"},3:{"a":"b","y":"z"}}

This should work for you:

{%- set account_id_list = [1,2,3,4,5,6,7] -%}

{%- set tag_dict = {1:{"a":"b","y":"z"},2:{"a":"b","y":"z"},3:{"a":"b","y":"z"}} -%}

{% for value in account_id_list %}
  {{ tag_dict[value] }}
{% endfor %}
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • Yes, this is what I was looking for Neil, thanks. Now that i have got the values for the corresponding key, will break the value and get the data from there. Actually my data inside the dictionary is "key":"CI", "Value":"122" which means CI = 122 – Yash Kamdar Jun 23 '23 at 04:26