human
What is a code to cost to make a string Panagram and the other steps required given the following:
Cost to make a string Panagram | Set 2 | Function to return the cost to make string a Panagram.
Count the occurrences of each lowercase character.
To store the total gain.
If some character is missing , it has to be added at twice the cost.
If some character appears more than once all of its occurrences except 1 can be traded for some gain.
If gain is more than the cost.
Return the total cost if gain < 0.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to cost to make a string Panagram and the other steps required.
 def costToPanagram ( string , cost ) :
	n = len ( string )
	occurrences = [ 0 ] * 26
	for i in range ( n ) :
		occurrences [ ord ( string [ i ] ) - ord ( ' a ' ) ] += 1
	gain = 0
	for i in range ( 26 ) :
		if occurrences [ i ] == 0 :
			gain -= 2 * cost [ i ]
		elif occurrences [ i ] > 1 :
			gain += cost [ i ] * ( occurrences [ i ] - 1 )
	if gain >= 0 :
		return 0
	return gain * - 1
if __name__ == " _ _ main _ _ " :
	cost = [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]
	string = " geeksforgeeks "
	print ( costToPanagram ( string , cost ) )