Replace the condition | SoloLearn: Learn to code for FREE!

+3

Replace the condition

[print(i*j) for i in range(5) for j in range(6,10) if i%3!=0 and j%3!=0] Is there any way to short this code? I'm looking for something which can replace ( i%3!=0 and j%3!=0 ) condition Like x in (i,j) and x%3!=0 (just an example not a part) or something else

4 Answers

New Answer

+5

you can eliminate "and" like: [print(i*j) for i in range(5) for j in range(6,10) if j*i%3!=0]

+2

Bahha🐧 and 'j*i%3!=0' is simply equal to 'j*i%3', since booleans are integers!

+2

Théophile 👍

+1

Actually, I don't think this expression is shorter, but is this what you're looking for? [ print(i*j) for i in range(5) for j in range(6,10) if all(x%3!=0 for x in [i, j]) ]