我说Python中有一个字符串 The quick @red fox jumps over the @lame brown dog.
我试图用一个@以单词作为参数的函数的输出替换每个开头的单词.
def my_replace(match):
return match + str(match.index('e'))
#Psuedo-code
string = "The quick @red fox jumps over the @lame brown dog."
string.replace('@%match', my_replace(match))
# Result
"The quick @red2 fox jumps over the @lame4 brown dog."
Run Code Online (Sandbox Code Playgroud)
有一个聪明的方法来做到这一点?