Explanation needed | Sololearn: Learn to code for FREE!


Explanation needed

a=[i for i in range(2,101) if all(i%j!=0 for j in range(2,i))] Here in first loop 2 gets divided by 2 itself so remainder is zero, which doesnt satisfy the condition and same is applicable for every prime number, we get one 0 in last. Then also we get a list of prime number. why is it so? Thank you in advance :)

6/19/2018 8:15:28 PM

Amrish Mishra

1 Answer

New Answer


for i = 2, j in range(2,2) so no range so 2 passes if test. for i = 3, j in range(2,3) so [2] so 3 passes if test. for i = 4, j in range(2,4) so [2,3] so 4 fails if test as 4%2 is 0.