title: How to get REALLY fast Python over a simple loop
body: <p>I'm working on a <a href="http://en.wikipedia.org/wiki/SPOJ" rel="nofollow noreferrer">SPOJ</a> problem, <a href="http://www.spoj.pl/problems/INTEST/" rel="nofollow noreferrer">INTEST</a>.  The goal is to specify the number of test cases (n) and a divisor (k), then feed your program n numbers.  The program will accept each number on a newline of stdin and after receiving the nth number, will tell you how many were divisible by k.</p>
  
  <p>The only challenge in this problem is getting your code to be FAST because <code>k</code> can be anything up to 10^7 and <code>n</code> can be as high as 10^9.</p>
  
  <p>I'm trying to write it in Python and have trouble speeding it up.  Any ideas?</p>
  
  <hr>
  
  <p>Edit 2: I finally got it to pass at 10.54 seconds.  I used nearly all of your answers to get there, and thus it was hard to choose one as 'correct', but I believe the one I chose sums it up the best.  Thanks to you all.  Final passing code is below.</p>
  
  <p>Edit:  I included some of the suggested updates in the included code.</p>
  
  <hr>
  
  <p>Extensions and third-party modules are not allowed.  The code is also run by the SPOJ judge machine, so I do not have the option of changing interpreters.</p>
  
  <pre><code>import sys
  import psyco
  psyco.full()
  
  def main():
      from sys import stdin, stdout
      first_in = stdin.readline()
      thing = first_in.split()
      n = int(thing[0])
      k = int(thing[1])
      total = 0
  
      list = stdin.readlines()
      for item in list:
          if int(item) % k == 0:
              total += 1
  
      stdout.write(str(total) + "\n")
  
  if __name__ == "__main__":
      main()
  </code></pre>