Because q contains squares
In [2]: q Out[2]: [4, 16]
and lambda x: x % 4 == 0 will return True for both of them:
In [3]: 4 % 4 == 0 Out[3]: True In [4]: 16 % 4 == 0 Out[4]: True
The integer number of columns contains after , which is not true for 2 (2% 4 is 2):
In [5]: 2 % 4 == 0 Out[5]: False
Therefore, 2 * 2 = 4 will not be included in the list.
In short, if you want the same behavior, change your understanding of the list to square numbers before calculating the remainder:
[x * x for x in range(2, 5, 2) if pow(x, 2, 4) == 0]
source share