Ask Your Question

Checking multiple things with an if else statement

asked 2022-01-30 20:21:14 +0200

Rune gravatar image

Is there a way to check multiple things in an if statement? I have a program in which I want to check if the degree of the lowest term of a polynomial is equal the degree of the lowest term of any polynomial in another list of polynomials. Essentially, what I have so far is:

def W(i):
for w in range(0,d[i]):
    if ListBasis[i][w].polynomial().ord() notequal ListBasis[i-1][y].polynomial.ord():
return d

And what I would like to have is

def W(i):
for w in range(0,d[i]):
    if for y in range(0,d[i]) ListBasis[i][w].polynomial().ord() notequal ListBasis[i-1][y].polynomial.ord():
return F

Clearly this is not the correct syntax for this, but I do not know what is.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-01-30 20:24:49 +0200

Max Alekseyev gravatar image

Python's all() and any() functions are your friends here:

if all(ListBasis[i][w].polynomial().ord() != ListBasis[i-1][y].polynomial.ord() for w in range(d[i])):
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2022-01-30 20:21:14 +0200

Seen: 209 times

Last updated: Jan 30 '22