code: def lks_2samp (data1,data2):
      
      j1 = 0
      j2 = 0
      fn1 = 0.0
      fn2 = 0.0
      n1 = len(data1)
      n2 = len(data2)
      en1 = n1
      en2 = n2
      d = 0.0
      data1.sort()
      data2.sort()
      while j1 < n1 and j2 < n2:
          d1=data1[j1]
          d2=data2[j2]
          if d1 <= d2:
              fn1 = (j1)/float(en1)
              j1 = j1 + 1
          if d2 <= d1:
              fn2 = (j2)/float(en2)
              j2 = j2 + 1
          dt = (fn2-fn1)
          if math.fabs(dt) > math.fabs(d):
              d = dt
      try:
          en = math.sqrt(en1*en2/float(en1+en2))
          prob = ksprob((en+0.12+0.11/en)*abs(d))
      except:
          prob = 1.0
      return d, prob
docs: Computes the Kolmogorov-Smirnof statistic on 2 samples.  From
  Numerical Recipies in C, page 493.
  
  Usage:   lks_2samp(data1,data2)   data1&2 are lists of values for 2 conditions
  Returns: KS D-value, associated p-value