samedi 18 septembre 2021

Why I'm getting error if i use for loop inside if statement

I want to run this loop But it is giving me syntax error. Why is it wrong?

l = [1,2,3,45,5,6,177,9,8];
i = 0;
if l[i] < l[for j in range(1,9)]:
    i=i+1

I have a list l which i want to iterate. is there any other way to run a loop like this?

Error:

  File "<ipython-input-12-c82841ff4cef>", line 3
    if l[i] < l[for j in range(1,9)]:
                ^
SyntaxError: invalid syntax

Aucun commentaire:

Enregistrer un commentaire