I have 3 API\'s that return json data to 3 dictionary variables. I am taking some of the values from the dictionary to process them. I read the specific values that I want t
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