instance for the specific code share all primes less than a given number of Python calculation, for your reference, the specific contents are as follows: firstly,

code ideas listed within the specified range of all candidates, and then successively from front to back and select a number to remove all the figures behind, can certainly not be divisible by the number, the digital filter, and then repeat the process until the divisor is greater than the maximum number of square root. The code mainly demonstrates the usage of the built-in function filter () and slicing. In fact, the efficiency of the algorithm is not very high.

 def primes2 (maxNumber): 'screening method to obtain all primes' # less than maxNumber to judge whether the integer LST = list (range (3, maxNumber, 2)) # maximum integer square root M = int (maxNumber**0.5) for index in range (m): current = lst[index] # if the current number is is greater than the maximum integer square root, the end of if current > m: break judgment; # filter lst[index+1:] = list to the position after the element (filter (lambda x: 0 if not x%current else x, lst[index+1:])) #2 all above is return [2] + LST 

prime is this, we hope to learn some help, I hope you will support a script.

you might be interested in this article:

This concludes the body part

This paper fixed link: | Script Home | +Copy Link

Article reprint please specify:Python uses a filter to calculate all prime numbers less than a given number | Script Home

You may also be interested in these articles!