Use python to implement some pattern search alg.