human
Modify string by inserting characters such that every K | Function to replace all ' ? ' characters in a string such that the given conditions are satisfied.
Traverse the string to Map the characters with respective positions.
Traverse the string again and replace all unknown characters.
If i % k is not found in the Map M , then return - 1.
Update S [ i ].
Print the string S.
Driver Code"
How can the above be solved in Python?
 ... Can you provide a code to modify string by inserting characters such that every K and the other steps required?
assistant
#Here is code to modify string by inserting characters such that every K and the other steps required.
 def fillString ( s , k ) :
	mp = { }
	for i in range ( len ( s ) ) :
		if ( s [ i ] != ' ? ' ) :
			mp [ i % k ] = s [ i ]
	s = list ( s )
	for i in range ( len ( s ) ) :
		if ( ( i % k ) not in mp ) :
			print ( - 1 )
			return
		s [ i ] = mp [ i % k ]
	s = ' ' . join ( s )
	print ( s )
if __name__ == ' _ _ main _ _ ' :
	S = " ? ? ? ? abcd "
	K = 4
	fillString ( S , K )