相关疑难解决方法(0)

Python用函数输出替换字符串模式

我说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)

有一个聪明的方法来做到这一点?

python regex

52
推荐指数
3
解决办法
2万
查看次数

标签 统计

python ×1

regex ×1