I have a question I need to resolve, for example:
s1 = "1$<2d>46<2e>5"
str_dict = {
"<2c>": ",",
"<2e>": ".",
"<2f>": "/",
"<2d>": "-",
"<2b>": "+",
"<3d>": "=",
"<3f>": "?",
"<2a>": "*",
"<5d>": "]",
"<40>": "@",
"<23>": "#",
"<25>": "%",
"<5e>": "^",
"<26>": "&",
"<5f>": "_",
"<5c>": "\\",
"<24>": "$",
}
def str_replace(source):
target = source
for k, v in str_dict.items():
if k in source:
target = source.replace(k, v)
str_replace(target)
return target
I want to replace these special str
in s1
into their dict'
s value.
str_replace(source)
is my function
but if the special str
is more than one in s1
, it just replaces the first place