human
Write me a code to total length of string from given Array of strings composed using given characters and the other steps required given the following:
Total length of string from given Array of strings composed using given characters | Function to count the total length.
Unordered_map for keeping frequency of characters.
Calculate the frequency.
Iterate in the N strings.
Iterates in the string.
Checks if given character of string string appears in it or not.
Adds the length of string if all characters are present.
Return the final result.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to total length of string from given Array of strings composed using given characters and the other steps required.
 def countCharacters ( arr , chars ) :
	res = 0
	freq = dict ( )
	for i in range ( len ( chars ) ) :
		freq [ chars [ i ] ] = freq . get ( chars [ i ] , 0 ) + 1
	for st in arr :
		flag = True
		for c in st :
			if ( c not in freq ) :
				flag = False
				break
		if ( flag ) :
			res += len ( st )
	return res
if __name__ == ' _ _ main _ _ ' :
	arr = [ " hi " , " data " , " geeksforgeeks " ]
	chars = " tiadhae "
	print ( countCharacters ( arr , chars ) )