def kmp_table(word):
 pos = 2
 cnd = 0
 table = list()
 table.append((-1))
 table.append(0)
 while (pos < len(word)):
  if (word[(pos - 1)] == word[cnd]):
   cnd = (cnd + 1)
   table.append(cnd)
   pos = (pos + 1)
  elif (cnd > 0):
   cnd = table[cnd]
  else:
   table.append(0)
   pos = (pos + 1)
 return table

def kmp_table ( word ) : pos = 2 cnd = 0 table = list ( ) table . append ( ( - 1 ) ) table . append ( 0 ) while ( pos < len ( word ) ) : if ( word [ ( pos - 1 ) ] == word [ cnd ] ) : cnd = ( cnd + 1 ) table . append ( cnd ) pos = ( pos + 1 ) elif ( cnd > 0 ) : cnd = table [ cnd ] else : table . append ( 0 ) pos = ( pos + 1 ) return table
build the partial match table of the knuth-morris-pratt algorithm .