human
Determine the winner of a game of deleting Characters from a String | Function to find the winner of the game when both players play optimally.
Stores the frequency of all digit.
Stores the scores of player1 and player2 respectively.
Iterate to store frequencies.
Turn for the player1.
Add score of player1.
Add score of player2.
Check if its a draw.
If score of player 1 is greater.
Otherwise.
Driver code"
How can the above be solved in Python?
 What is a code to determine the winner of a game of deleting Characters from a String and the other steps required?
assistant
#Here is code to determine the winner of a game of deleting Characters from a String and the other steps required.
 def determineWinner ( str ) :
	A = [ 0 for i in range ( 9 ) ] ;
	sum1 = 0 ; sum2 = 0 ;
	for i in range ( 0 , len ( str ) ) :
		A [ int ( str [ i ] ) ] += 1 ;
	for i in range ( 0 , 9 ) :
		if ( i % 2 != 0 ) :
			sum1 = sum1 + A [ i ] ;
		else :
			sum2 = sum2 + A [ i ] ;
	if ( sum1 == sum2 ) :
		print ( " - 1" ) ;
	elif ( sum1 > sum2 ) :
		print ( " Player ▁ 1" ) ;
	else :
		print ( " Player ▁ 2" ) ;
if __name__ == ' _ _ main _ _ ' :
	str = "78787" ;
	determineWinner ( str ) ;