As I stumbled upon the same problem and Simon's answer was the one that helped me to solve my case, I thought of showing an easier example just for clarification:
from collections import defaultdict
And then for the translation, say you'd like to remove '@' and '\r' characters:
remove_chars_map = defaultdict()
remove_chars_map['@'] = None
remove_chars_map['\r'] = None
new_string = old_string.translate(remove_chars_map)
And an example:
old_string = "word1@\r word2@\r word3@\r"
new_string = "word1 word2 word3"
'@' and '\r' removed
As I stumbled upon the same problem and Simon's answer was the one that helped me to solve my case, I thought of showing an easier example just for clarification:
from collections import defaultdict
And then for the translation, say you'd like to remove '@' and '\r' characters:
remove_chars_map = defaultdict()
remove_chars_map['@'] = None
remove_chars_map['\r'] = None
new_string = old_string.translate(remove_chars_map)
And an example:
old_string = "word1@\r word2@\r word3@\r"
new_string = "word1 word2 word3"
'@' and '\r' removed
As I stumbled upon the same problem and Simon's answer was the one that helped me to solve my case, I thought of showing an easier example just for clarification:
from collections import defaultdict
And then for the translation, say you'd like to remove '@' and '\r' characters:
remove_chars_map = defaultdict()
remove_chars_map['@'] = None
remove_chars_map['\r'] = None
new_string = old_string.translate(remove_chars_map)
And an example:
old_string = "word1@\r word2@\r word3@\r"
new_string = "word1 word2 word3"
'@' and '\r' removed
As I stumbled upon the same problem and Simon's answer was the one that helped me to solve my case, I thought of showing an easier example just for clarification:
from collections import defaultdict
And then for the translation, say you'd like to remove '@' and '\r' characters (like me :-) ):
remove_chars_map = defaultdict()
remove_chars_map['\r']remove_chars_map['@'] = None
remove_chars_map['\n']remove_chars_map['\r'] = None
new_string = old_string.translate(remove_chars_map)
And an example:
old_string = "word1\r word2\r word3\r\n""word1@\r word2@\r word3@\r"
new_string = "word1 word2 word3"
'\r''@' and '\n''\r' removed
As I stumbled upon the same problem and Simon's answer was the one that helped me to solve my case, I thought of showing an easier example just for clarification:
from collections import defaultdict
And then for the translation, say you'd like to remove '\r' characters (like me :-) ):
remove_chars_map = defaultdict()
remove_chars_map['\r'] = None
remove_chars_map['\n'] = None
new_string = old_string.translate(remove_chars_map)
And an example:
old_string = "word1\r word2\r word3\r\n"
new_string = "word1 word2 word3"
'\r' and '\n' removed
As I stumbled upon the same problem and Simon's answer was the one that helped me to solve my case, I thought of showing an easier example just for clarification:
from collections import defaultdict
And then for the translation, say you'd like to remove '@' and '\r' characters:
remove_chars_map = defaultdict()
remove_chars_map['@'] = None
remove_chars_map['\r'] = None
new_string = old_string.translate(remove_chars_map)
And an example:
old_string = "word1@\r word2@\r word3@\r"
new_string = "word1 word2 word3"
'@' and '\r' removed
As I stumbled upon the same problem and Simon's answer was the one that helped me to solve my case, I thought of showing an easier example just for clarification:
from collections import defaultdict
And then for the translation, say you'd like to remove '\r' characters (like me :-) ):
remove_chars_map = defaultdict()
remove_chars_map['\r'] = None
remove_chars_map['\n'] = None
new_string = old_string.translate(remove_chars_map)
And an example:
old_string = "word1\r word2\r word3\r\n"
new_string = "word1 word2 word3"
'\r' and '\n' removed