+ 1
what is line 5 means?
3 Respostas
+ 9
x & 1 produces a value that is either 1 or 0, depending on the least significant bit of x: if the last bit is 1, the result of x & 1 is 1; otherwise, it is 0. This is a bitwise AND operation.
So every number [0, 3, 6, 9 , 12....] lsb is checked and if if the bit is 1 return 1 else 0 so
3 = 11 lsb is 1 so output 1
6 = 110 lsb is 0 so output 0
9 = 1001 lsb is 1 so output 1 this way it is working in line 5
And before that list range 0 to 17 where multiply with 3 is done in the range numbers
Ansab Khan then sum of that eight ones is done which is gives final result as 8
+ 5
Line 5 is list comprehension.
What's happening is that the loop is iterating over the list 'l' and each element of list is assigned to variable 'x' which is checked if it is even or odd using Bitwise AND operator. The result of each check is stored in the list 'm'.
The sum of 8 one's is 8 obviously.
+ 1
thanks nAutAxH AhmAd and GAWEN STEASY