0

I try to use two for loops in one line with condition
but it did not recognize the i value

 pack = [a,b,c]
    answer =[x== y for x,y in zip(i * int(len(answers)/len(i)) if len(answers)%len(i) ==0  else  i * int(len(answers)/len(i)+1),answers) for i in pack]

and it returns the message

----> 7 answer =[x== y for x,y in zip(i * int(len(answers)/len(i)) if len(answers)%len(i) ==0 else i * int(len(answers)/len(i)+1),answers) for i in pack] 8 9 answer = [i+1 for i, j in enumerate(answer) if j == max(answer)]

NameError: name 'i' is not defined

1 Answers1

0

'Single Line Nested For Loops'

I believe the answer from this linked question will help out overall for the nested loop piece. For the name error with the "i" variable, you are trying to use the variable outside of the scope it is defined.

You essentially have:

for x, y in zip
{
//where you are trying to use the variable i before it exists
} 

for i in packs
{
} 
eparham7861
  • 205
  • 3
  • 12