Ask Your Question
1

Checking multiple things with an if else statement

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

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):
d=set()
for w in range(0,d[i]):
    if ListBasis[i][w].polynomial().ord() notequal ListBasis[i-1][y].polynomial.ord():
        d.add(ListBasis[i][w])
    else:
return d

And what I would like to have is

def W(i):
F=set()
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():
        F.add(ListBasis[i][w])
    else:
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
1

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

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])):
        d.add(ListBasis[i][w])
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

Stats

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

Seen: 381 times

Last updated: Jan 30 '22