code: def rabin_karp_matching(s, t):
      
      hash_s = 0
      hash_t = 0
      len_s = len(s)
      len_t = len(t)
      last_pos = pow(DOMAIN, len_t - 1) % PRIME
      if len_s < len_t:
          return -1
      for i in range(len_t):         # preprocessing
          hash_s = (DOMAIN * hash_s + ord(s[i])) % PRIME
          hash_t = (DOMAIN * hash_t + ord(t[i])) % PRIME
      for i in range(len_s - len_t + 1):
          if hash_s == hash_t:       # check character by character
              if matches(s, t, i, 0, len_t):
                  return i
          if i < len_s - len_t:
              hash_s = roll_hash(hash_s, ord(s[i]), ord(s[i + len_t]),
                                 last_pos)
      return -1
docs: Find a substring by Rabin-Karp
  
      :param s: the haystack string
      :param t: the needle string
  
      :returns: index i such that s[i: i + len(t)] == t, or -1
      :complexity: O(len(s) + len(t)) in expected time,
                  and O(len(s) * len(t)) in worst case