code: def lkendalltau(x,y):
      
      n1 = 0
      n2 = 0
      iss = 0
      for j in range(len(x)-1):
          for k in range(j,len(y)):
              a1 = x[j] - x[k]
              a2 = y[j] - y[k]
              aa = a1 * a2
              if (aa):             # neither list has a tie
                  n1 = n1 + 1
                  n2 = n2 + 1
                  if aa > 0:
                      iss = iss + 1
                  else:
                      iss = iss -1
              else:
                  if (a1):
                      n1 = n1 + 1
                  else:
                      n2 = n2 + 1
      tau = iss / math.sqrt(n1*n2)
      svar = (4.0*len(x)+10.0) / (9.0*len(x)*(len(x)-1))
      z = tau / math.sqrt(svar)
      prob = erfcc(abs(z)/1.4142136)
      return tau, prob
docs: Calculates Kendall's tau ... correlation of ordinal data.  Adapted
  from function kendl1 in Numerical Recipies.  Needs good test-routine.@@@
  
  Usage:   lkendalltau(x,y)
  Returns: Kendall's tau, two-tailed p-value