7-9. Translation
(a) writing a character translation program (functionally similar to the TR command in Unix). We call this function tr (), which has
Three string parameters: source string, Destination string, basic string, syntax is defined as follows:
def tr (Srcstr, DSTSTR, String)
The content of Srcstr is the character set that you intend to "translate", Dsrstr is the character set that is obtained after translation, and string is
The string to which you intend to perform the translation operation. For example, if srcstr = = ' abc ', DSTSTR = = ' MnO ', string = =
' ABCdef ', then the output of TR () will be ' mnodef '. Note here len (srcstr) = = Len (dststr).
In this exercise, you can use the built-in function Chr () and Ord (), but they are not necessarily the solution to this problem.
A few functions are available.
(b) Add a marker parameter to this function to handle the case-insensitive translation problem.
(c) Modify your program so that it can handle the operation of deleting characters. The string srcstr cannot be mapped to a string dststr
The extra characters in the characters will be filtered out. In other words, these characters do not map to any of the characters in the DSTSTR string, because
This is filtered out of the word character returned from the function. For example: if srcstr = = ' ABCdef ', dststr = = ' MnO ',
string = = ' Abcdefghi ', then TR () will output ' Mnoghi '. Note here len (srcstr) >= len (DSTSTR).
def tr (srcstr,dststr,string,flag): return Dststr.join (String.Split (SRCSTR))
- Since my understanding is the need to replace the whole word, I do not think of a suitable method, waiting for the study of the regular time. Cond.
7.9 Unanswered