▁relative ▁to ▁the ▁▁▁▁ ▁text ▁T ▁is ▁len ( P ) ▁- ▁F [ i ] ▁for ▁a ▁mismatch ▁occurr ing ▁at ▁i - 1 . ▁▁▁▁ ▁""" ▁▁▁▁ ▁F ▁= ▁[ 0 ▁for ▁c ▁in ▁S ] ▁▁▁▁ ▁Z ▁= ▁fundamental _ pre process ( S ) ▁▁▁▁ ▁longest ▁= ▁ 0 ▁▁▁▁ ▁for ▁i , ▁zv ▁in ▁enumerate ( re vers ed ( Z )): ▁▁▁▁▁▁▁▁ ▁longest ▁= ▁max ( z v , ▁longest ) ▁if ▁zv ▁== ▁i ▁+ ▁ 1 ▁else ▁longest ▁▁▁▁▁▁▁▁ ▁F [- i - 1 ] ▁= ▁longest ▁▁▁▁ ▁return ▁F ▁ ▁def ▁string _ search ( P , ▁T ) ▁-> ▁List [ int ]: ▁▁▁▁ ▁""" ▁▁▁▁ ▁Im plementation ▁of ▁the ▁Bo yer - Mo ore ▁string ▁search ▁algorithm . ▁This ▁finds ▁all ▁occurr ences ▁of ▁P ▁▁▁▁ ▁in ▁T , ▁and ▁incorpor ates ▁numerous ▁ways ▁of ▁pre - processing ▁the ▁pattern ▁to ▁determine ▁the ▁optimal ▁▁▁▁ ▁amount ▁to ▁shift ▁the ▁string ▁and ▁skip ▁compar isons . ▁In ▁practice ▁it ▁runs ▁in ▁O ( m ) ▁( and ▁even ▁▁▁▁ ▁sub linear ) ▁time , ▁where ▁m ▁is ▁the ▁length ▁of ▁T . ▁This ▁implementation ▁performs ▁a ▁case - ins ens itive ▁▁▁▁ ▁search ▁on ▁ASCII ▁al ph ab etic ▁characters , ▁spaces ▁not ▁included . ▁▁▁▁ ▁""" ▁▁▁▁ ▁if ▁len ( P ) ▁== ▁ 0 ▁or ▁len ( T ) ▁== ▁ 0 ▁or ▁len ( T ) ▁< ▁len ( P ): ▁▁▁▁▁▁▁▁ ▁return ▁[] ▁▁▁▁▁ ▁matches ▁= ▁[] ▁▁▁▁▁ ▁#