Generate all possible strings formed by replacing letters with given respective symbols | Function to generate all possible string by replacing the characters with mapped symbols ; Base Case ; Function call with the P - th character not replaced ; Replace the P - th character ; Function call with the P - th character replaced ; Driver Code ; Function Call
def generateLetters ( S , P , M ) : NEW_LINE INDENT if ( P == len ( S ) ) : NEW_LINE INDENT print ( S ) ; NEW_LINE return NEW_LINE DEDENT generateLetters ( S , P + 1 , M ) ; NEW_LINE S = S . replace ( S [ P ] , M [ S [ P ] ] ) NEW_LINE generateLetters ( S , P + 1 , M ) ; NEW_LINE DEDENT S = " aBc " ; NEW_LINE M = { } ; NEW_LINE M [ ' a ' ] = ' $ ' NEW_LINE M [ ' B ' ] = ' # ' NEW_LINE M [ ' c ' ] = ' ^ ' NEW_LINE M [ ' d ' ] = ' & ' NEW_LINE M [ '1' ] = ' * ' NEW_LINE M [ '2' ] = ' ! ' NEW_LINE M [ ' E ' ] = ' @ ' NEW_LINE generateLetters ( S , 0 , M ) ; NEW_LINE