我有一个 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."
有什么聪明的办法吗?