I have a 2 list:
a = ['user','user2','user','user2']
b = ['value1','value1','value2','value1']
Is it possible to merge both and add "_" in between them
Looking for result:
result = ['user_value1','user2_value1','user_value2','user2_value1']
length of both lists will be same.
tried below no luck:(based on link Combine two lists and alternating the result in Jinja?
{%- set a = ['user1','user2','user3','user4'] -%}
{%- set b = ['value1','value2','value3','value4'] -%}
{%- set combined = (a,b) -%}
{%- set lengths = [] %}
{%- for row in combined -%}{%- if lengths.append(row|length)-%}{%- endif -%}{%- endfor -%}
{%- set max_length = (lengths|sort)[-1] -%}
{%- set rows = [] -%}
{%- for r in range(max_length) -%}
{%- for a in combined -%}
{%- if a[r] -%}{%- if rows.append(a[r]) -%}{%- endif -%}{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{{ rows }}
thank you!