0

If here someone who can explain this..

y=10 w=30 print([i for i in range(y,w,3) if i%2==1][2]) answer -25 plz explain

17th Aug 2018, 3:54 PM
Harsh Mamgai
Harsh Mamgai - avatar
5 Answers
+ 1
Harsh Mamgai the original list has the powers of 2 from 0 to 3 (0, 1, 4, 9) then it is filtered to even numbers (0, 4) and 0 + 4 is 4, so the answer is 4
17th Aug 2018, 8:53 PM
hinanawi
hinanawi - avatar
+ 2
i'm getting 25, not -25 and here's the logic: the code lists all the numbers between 10 and 30 with a step of 3 (10, 13, 16, 19, 22, 25, 28) but here they are filtered to only be odd numbers (13, 19, 25) so, the third element is 25
17th Aug 2018, 4:13 PM
hinanawi
hinanawi - avatar
+ 1
thanks 😘😘
17th Aug 2018, 4:22 PM
Harsh Mamgai
Harsh Mamgai - avatar
0
here one question more for you. r=[j**2 for j in range (4) if j**2%2 ==0] print (r[0]+r[1])
17th Aug 2018, 4:25 PM
Harsh Mamgai
Harsh Mamgai - avatar
0
answer is 4 plz explain
17th Aug 2018, 4:33 PM
Harsh Mamgai
Harsh Mamgai - avatar