human
Write me a code to find all strings formed from characters mapped to digits of a number and the other steps required given the following:
Find all strings formed from characters mapped to digits of a number | Function to find all strings formed from a given number where each digit maps to given characters ..
vector of strings to store output.
stores index of first occurrence of the digits in input.
maintains index of current digit considered.
for each digit.
store index of first occurrence of the digit in the map.
clear vector contents for future use.
do for each character thats maps to the digit.
for first digit , simply push all its mapped characters in the output list.
from second digit onwards.
for each string in output list append current character to it ..
convert current character to string.
Imp - If this is not the first occurrence of the digit , use same character as used in its first occurrence.
store strings formed by current digit.
nothing more needed to be done if this is not the first occurrence of the digit.
replace contents of output list with temp list.
Driver Code.
vector to store the mappings.
vector to store input number.
print all possible strings"
How can the above be solved in Python?
assistant
#Here is code to find all strings formed from characters mapped to digits of a number and the other steps required.
 def findCombinations ( input : list , table : list ) -> list :
	out , temp = [ ] , [ ]
	mp = dict ( )
	index = 0
	for d in input :
		if d not in mp :
			mp [ d ] = index
		temp . clear ( )
		for i in range ( len ( table [ d - 1 ] ) ) :
			if index == 0 :
				s = table [ d - 1 ] [ i ]
				out . append ( s )
			if index > 0 :
				for string in out :
					s = table [ d - 1 ] [ i ]
					if mp [ d ] != index :
						s = string [ mp [ d ] ]
					string = string + s
					temp . append ( string )
				if mp [ d ] != index :
					break
		if index > 0 :
			out = temp . copy ( )
		index += 1
	return out
if __name__ == " _ _ main _ _ " :
	table = [ [ ' A ' , ' B ' , ' C ' ] , [ ' D ' , ' E ' , ' F ' ] , [ ' G ' , ' H ' , ' I ' ] , [ ' J ' , ' K ' , ' L ' ] , [ ' M ' , ' N ' , ' O ' ] , [ ' P ' , ' Q ' , ' R ' ] , [ ' S ' , ' T ' , ' U ' ] , [ ' V ' , ' W ' , ' X ' ] , [ ' Y ' , ' Z ' ] ]
	input = [ 1 , 2 , 1 ]
	out = findCombinations ( input , table )
	for it in out :
		print ( it , end = " ▁ " )