title: How to get python dictionary or list from Jinja templated string in Airflow?
body: <p>Let's assume I've an operator which needs a python list (or dict) as an argument for it's property</p>
  <pre><code>doExampleTask = ExampleOperator(
      task_id             = &quot;doExampleTask&quot;,
      property_needs_list = [
                              (&quot;a&quot;, &quot;x&quot;),
                              (&quot;b&quot;, &quot;y&quot;)
                            ],
      property_needs_dict = {
                              &quot;dynamic_field_1&quot;: &quot;dynamic_value&quot;,
                              # ...
                              &quot;dynamic_field_N&quot;: &quot;dynamic_value&quot;,
                            },
  )
  </code></pre>
  <p>The problem is that I can't define the python data structure of the list (how many list elements is needed) or the dict (which fields were generated) in the creation time of the DAG.</p>
  <p>I could only get this structure dynamically by executing a previous task or macro.</p>
  <ul>
  <li>the task could write the data structure with dynamic fields into the XCOM</li>
  <li>the macro could return a data structure</li>
  </ul>
  <p>But in both of the above cases there is no way to convert the dynamic data structure (which is returned by XCOM or custom macro) to python data structure and use it as a property of the operator.</p>
  <p>This will not return list or dict:</p>
  <pre><code>doExampleTask = ExampleOperator(
      task_id             = &quot;doExampleTask&quot;,
      property_needs_list = '{{ generate_list() }}',
      property_needs_dict = '{{ generate_dict() }}',
  )
  </code></pre>
  <p>This will also not return dict or list:</p>
  <pre><code>doExampleTask = ExampleOperator(
      task_id             = &quot;doExampleTask&quot;,
      property_needs_list = '{{ ti.xcom_pull(task_ids=&quot;PreviousTask&quot;, key=&quot;list_structure&quot;) }}',
      property_needs_dict = '{{ ti.xcom_pull(task_ids=&quot;PreviousTask&quot;, key=&quot;dict_structure&quot;) }}',
  )
  </code></pre>
  <p>If I use something like <code>eval()</code> function, it will not be able to evaluate the string argument in execution time of the Task. It will try to evaluate it in creation time of the DAG, but the values will obviously not be there.</p>
  <pre><code>doExampleTask = ExampleOperator(
      task_id             = &quot;doExampleTask&quot;,
      property_needs_list = eval('{{ ti.xcom_pull(task_ids=&quot;PreviousTask&quot;, key=&quot;list_structure&quot;) }}'),
      property_needs_dict = eval('{{ ti.xcom_pull(task_ids=&quot;PreviousTask&quot;, key=&quot;dict_structure&quot;) }}'),
  )
  </code></pre>
  <p>or</p>
  <pre><code>doExampleTask = ExampleOperator(
      task_id             = &quot;doExampleTask&quot;,
      property_needs_list = eval('{{ generate_list() }}'),
      property_needs_dict = eval('{{ generate_dict() }}'),
  )
  </code></pre>
  <p>How can I workaround this problem?<br />
  I'm mostly interested in Airflow 1.x, but I'm open to Aitflow 2.x solution.<br />
  Thank you!</p>