Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Solution: Prime numbers

Calculating the prime numbers

n = 50

nums = range(2, n)
for i in range(2, 1+int(n ** 0.5)):
    nums = filter(lambda x: x == i or x % i, nums)

print(nums)