title: Generating a list of prime numbers using list comprehension
body: <p>I'm trying to create a list of all the prime numbers less than or equal to a given number. I did that successfully using for loops. I was trying to achieve the same using list comprehension using python. But my output has some unexpected values. </p>
  
  <p>Here is my code..</p>
  
  <pre><code>pr=[2]
  pr+=[i for i in xrange(3,num+1) if not [x for x in pr if i%x==0]]
  </code></pre>
  
  <p>where <code>num</code> is the number I had taken as input from user.</p>
  
  <p>The output of the above code for </p>
  
  <pre><code>num=20 is this:  [2, 3, 5, 7, 9, 11, 13, 15, 17, 19]
  </code></pre>
  
  <p>I'm puzzled as to why 9 and 15 are there in the output. What am I doing wrong here?</p>