Try ERPNext Buy Support Partners Foundation

Iterate on multiple list in single for loop in Jinja

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

Anybody??

Would zip work?

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

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

2 Likes

@navdeepghai Thank you so much. :slight_smile:

it works, thanks!

1 Like