ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Iterate on multiple list in single for loop in Jinja


#1

Hi,
I need to iterate on multiple lists in a single loop,
here is what i’ve tried but its giving me the error

Tried :
toomanyvalues
Error :
ValueError : Too many values to unpack


#2

Anybody??


#3

Would zip work?


#4

I’ve already tried
for k,w,m in zip(kpi, weightage, marks_obtained)
but its giving error “Zip not found” something like this.


#5

I tried this work arround and it’s working fine for me.
May be it’ll work for you also.

list_1  = [1, 2,3,4]
list_2 = [1,2,3,4]
<table>
{% for i in list_1 %}
      {% set item_1 = list_1[loop.index-1] %}
      {% set item_2 = list_2[loop.index-1] %}
     <tr>
           <td> {{ item_1 }} </td>
           <td>  {{ item_2 }} </td>
    </tr>
{% endfor %}
  </table>

loop.index always start with index 1

NOTE:
Your all lists len must be balance or you can handle the condition for exception index out of range


#6

@navdeepghai Thank you so much. :slight_smile: