title: Find the nth lucky number generated by a sieve in Python
body: <p>I'm trying to make a program in Python which will generate the nth lucky number according to the <a href="http://en.wikipedia.org/wiki/Lucky_number" rel="noreferrer">lucky number sieve</a>. I'm fairly new to Python so I don't know how to do all that much yet. So far I've figured out how to make a function which determines all lucky numbers below a specified number:</p>
  
  <pre><code>def lucky(number):
      l = range(1, number + 1, 2)
      i = 1
      while i &lt; len(l):
          del l[l[i] - 1::l[i]]
          i += 1
      return l
  </code></pre>
  
  <p>Is there a way to modify this so that I can instead find the nth lucky number? I thought about increasing the specified number gradually until a list of the appropriate length to find the required lucky number was created, but that seems like a really inefficient way of doing it.</p>
  
  <p><strong>Edit:</strong> I came up with this, but is there a better way?</p>
  
  <pre><code>def lucky(number):
      f = 2
      n = number * f
      while True:
          l = range(1, n + 1, 2)
          i = 1
          while i &lt; len(l):
              del l[l[i] - 1::l[i]]
              i += 1
          if len(l) &gt;= number:
              return l[number - 1]
          f += 1
          n = number * f
  </code></pre>