Question: I came across this (really) simple program a while ago. It just outputs the first x primes. I'm embarrassed to ask, is there any way to make it more "pythonic" ie condense it while making it (more) readable? Switching functions is fine; I'm only interested in readability.

Thanks

```
from math import sqrt

def isprime(n):
  if n ==2:
    return True
  if n % 2 ==0 : # evens
    return False

  max = int(sqrt(n))+1 #only need to search up to sqrt n 
  i=3
  while i <= max: # range starts with 3 and for odd i
    if n % i == 0:
      return False
    i+=2

  return True

reqprimes = int(input('how many primes: '))
primessofar = 0
currentnumber = 2
while primessofar < reqprimes:

  result = isprime(currentnumber)

  if result:
     primessofar+=1
     print currentnumber
     #print '\n'

  currentnumber += 1

```

Answer: 
A few minor things from the [style guide](http://www.python.org/dev/peps/pep-0008/).

- Uses four spaces, not two. (Personally I prefer tabs, but that's not the Pythonic way.)
- Fewer blank lines.
- Consistent whitespace: `n ==2:` => `n == 2:`- Use underscores in your variables names: `currentnumber` => `current_number`
I recently found [Project Euler solutions in functional python](http://pyeuler.wikidot.com/start) and it has some really nice examples of working with primes like this. [Number 7](http://pyeuler.wikidot.com/problems-1-10) is pretty close to your problem:

```
def isprime(n):
    """Return True if n is a prime number"""
    if n < 3:
        return (n == 2)
    elif n % 2 == 0:
        return False
    elif any(((n % x) == 0) for x in xrange(3, int(sqrt(n))+1, 2)):
        return False
    return True

def primes(start=2):
    """Generate prime numbers from 'start'"""
    return ifilter(isprime, count(start))

```