human
Give me a code to minimum distance between duplicates in a String and the other steps required given the following:
Minimum distance between duplicates in a String | This function is used to find the required the minimum distances of repeating characters.
Define dictionary and list.
Traverse through string.
If character present in dictionary.
Difference between current position and last stored value.
Updating current position.
Storing difference in list.
If character not in dictionary assign it with initial of its position.
If no element inserted in list i . e . no repeating characters.
Return minimum distance.
Given Input.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to minimum distance between duplicates in a String and the other steps required.
 def shortestDistance ( S , N ) :
	dic = { }
	dis = [ ]
	for i in range ( N ) :
		if S [ i ] in dic :
			var = i - dic [ S [ i ] ]
			dic [ S [ i ] ] = i
			dis . append ( var )
		else :
			dic [ S [ i ] ] = i
	if ( len ( dis ) == 0 ) :
		return - 1
	else :
		return min ( dis ) - 1
S = " geeksforgeeks "
N = 13
print ( shortestDistance ( S , N ) )