python/data_mining/primes.py
def first(n):
    """Returns first n prime numbers.

    Args:
        n (int): the number of prime numbers ot return.

    Returns:
        ([int]): List of prime numbers.

    Source: Based on:
        https://www.daniweb.com/programming/software-development/threads/233730/to-find-first-n-prime-numbers
    """
    if n > 10000:
        raise ValueError("n must be smaller than 10,000")
    if n == 0:
        return []
    ten_thousandth_prime = 104729
    primes = []
    # Loop through 9999 possible prime numbers
    for a in xrange(1, ten_thousandth_prime):
        # Loop through every number it could divide by
        for b in range(2, a):
            # Does b divide evenly into a ?
            if a % b == 0:
                break
        # Loop exited without breaking ? (It is prime)
        else:
            # Add the prime number to our list
            primes.append(a)
        # We have enough to stop ?
        if len(primes) == n:
            return primes
Returns first n prime numbers.

    Args:
        n (int): the number of prime numbers ot return.

    Returns:
        ([int]): List of prime numbers.

    Source: Based on:
        https://www.daniweb.com/programming/software-development/threads/233730/to-find-first-n-prime-numbers
    
Returns first n prime numbers.
Returns first n prime numbers .
def first(n):
    if n > 10000:
        raise ValueError("n must be smaller than 10,000")
    if n == 0:
        return []
    ten_thousandth_prime = 104729
    primes = []
    for a in xrange(1, ten_thousandth_prime):
        for b in range(2, a):
            if a % b == 0:
                break
        else:
            primes.append(a)
        if len(primes) == n:
            return primes
def first ( n ) : if n > 10000 : raise ValueError ( "n must be smaller than 10,000" ) if n == 0 : return [ ] ten_thousandth_prime = 104729 primes = [ ] for a in xrange ( 1 , ten_thousandth_prime ) : for b in range ( 2 , a ) : if a % b == 0 : break else : primes . append ( a ) if len ( primes ) == n : return primes
Returns first n prime numbers.
Returns first n prime numbers .
"""Returns first n prime numbers.

    Args:
        n (int): the number of prime numbers ot return.

    Returns:
        ([int]): List of prime numbers.

    Source: Based on:
        https://www.daniweb.com/programming/software-development/threads/233730/to-find-first-n-prime-numbers
    """ # Loop through 9999 possible prime numbers # Loop through every number it could divide by # Does b divide evenly into a ? # Loop exited without breaking ? (It is prime) # Add the prime number to our list # We have enough to stop ?
List of prime numbers.
List of prime numbers .
([int])
n
the number of prime numbers ot return.
the number of prime numbers ot return .