title: How to cycle through a defined list of elements
body: <p>I have a large dictionary of lists which is generated dynamically as part of a larger python program. This is an example of what the dictionary looks like</p>
  <pre class="lang-py prettyprint-override"><code>params = {
  'output': ['quantity_tot_1m', 'quantity_tot_3m', 'quantity_tot_6m',
  'quantity_tot_12m', 'quantity_tot_full', 'cost_tot_1m', 'cost_tot_3m', 'cost_tot_6m', 'cost_tot_12m', 'cost_tot_full', 'selling_tot_1m', 
  'selling_tot_3m', 'selling_tot_6m', 'selling_tot_12m', 'selling_tot_full', 'profit_tot_1m', 'profit_tot_3m', 'profit_tot_6m', 'profit_tot_12m', 'profit_tot_full'], 
  'agg_types': ['By SKU - 01 Month','By SKU - 03 Months','By SKU - 06 Months','By SKU - 12 Months']
  }
  </code></pre>
  <p>I need assistance being able to cycle over these lists</p>
  <p>I have tried the below</p>
  <pre class="lang-py prettyprint-override"><code>from jinjasql import JinjaSql
  j = JinjaSql(param_style='pyformat')
  
  QUERY_TEMPLATE = &quot;&quot;&quot;
  {% set mix_agg = agg_types|replace(&quot;[&quot;,&quot;&quot;)|replace(&quot;]&quot;,&quot;&quot;) %}
  {% set mix_agg2 = cycler(mix_agg) %}
  {% for o in output %}
  ROUND(CAST(SUM(CASE WHEN agg_type = '{{ mix_agg2.next() | sqlsafe }}' THEN profit_tot ELSE 0 END ) AS NUMERIC),2) AS {{o | sqlsafe}} {% endfor%}
  &quot;&quot;&quot;
  
  query, bind_params = j.prepare_query(QUERY_TEMPLATE, params)
  print(query)
  </code></pre>
  <p>This doesn't cycle over the list, it merely outputs the list as is. Of course I cannot explicitly type the list into the cycler because this has to be dynamic.</p>
  <p>Perhaps a <code>cycler()</code> isn't the best approach but I need an output like the below:</p>
  <pre class="lang-sql prettyprint-override"><code>ROUND(CAST(SUM(CASE WHEN agg_type = 'By SKU - 01 Month' THEN profit_tot ELSE 0 END ) AS NUMERIC),2) AS profit_tot_1m,
  
  ROUND(CAST(SUM(CASE WHEN agg_type = 'By SKU - 03 Months' THEN profit_tot ELSE 0 END ) AS NUMERIC),2) AS profit_tot_3m,
  
  ROUND(CAST(SUM(CASE WHEN agg_type = 'By SKU - 06 Months' THEN profit_tot ELSE 0 END ) AS NUMERIC),2) AS profit_tot_6m,
  
  ROUND(CAST(SUM(CASE WHEN agg_type = 'By SKU - 12 Months' THEN profit_tot ELSE 0 END ) AS NUMERIC),2) AS profit_tot_12m
  </code></pre>
  <p>not like this:</p>
  <pre class="lang-sql prettyprint-override"><code>ROUND(CAST(SUM(CASE WHEN agg_type = 'By SKU - 01 Month', 'By SKU - 03 Months', 'By SKU - 06 Months', 'By SKU - 12 Months' THEN profit_tot ELSE 0 END ) AS NUMERIC),2) AS profit_tot_1m,
  
  ROUND(CAST(SUM(CASE WHEN agg_type = 'By SKU - 01 Month', 'By SKU - 03 Months', 'By SKU - 06 Months', 'By SKU - 12 Months' THEN profit_tot ELSE 0 END ) AS NUMERIC),2) AS profit_tot_3m,
  
  ROUND(CAST(SUM(CASE WHEN agg_type = 'By SKU - 01 Month', 'By SKU - 03 Months', 'By SKU - 06 Months', 'By SKU - 12 Months' THEN profit_tot ELSE 0 END ) AS NUMERIC),2) AS profit_tot_6m,
   
  ROUND(CAST(SUM(CASE WHEN agg_type = 'By SKU - 01 Month', 'By SKU - 03 Months', 'By SKU - 06 Months', 'By SKU - 12 Months' THEN profit_tot ELSE 0 END ) AS NUMERIC),2) AS profit_tot_12m
  </code></pre>
  <p>There are a total of 20 output columns <code>{{o | sqlsafe}}</code></p>