human
Give me a code to string hashing using Polynomial rolling hash function and the other steps required given the following:
String hashing using Polynomial rolling hash function | Function to calculate the hash of a string.
P and M.
Loop to calculate the hash value by iterating over the elements of string.
Driver Code.
Given string"
Solution in Python:
assistant
#Here is code to string hashing using Polynomial rolling hash function and the other steps required.
 def polynomialRollingHash ( str ) :
	p = 31
	m = 1e9 + 9
	power_of_p = 1
	hash_val = 0
	for i in range ( len ( str ) ) :
		hash_val = ( ( hash_val + ( ord ( str [ i ] ) - ord ( ' a ' ) + 1 ) * power_of_p ) % m )
		power_of_p = ( power_of_p * p ) % m
	return int ( hash_val )
if __name__ == ' _ _ main _ _ ' :
	str1 = " geeksforgeeks "
	print ( " Hash ▁ of ▁ ' { } ' ▁ = ▁ { } " . format ( str1 , polynomialRollingHash ( str1 ) ) )