小编Hel*_*lga的帖子

Python:用列表中的第i个元素替换x的出现


假设我们有一个a = "01000111000011"n=5 "1"s 的字符串.第i个 "1",我想替换为第i个角色"ORANGE".我的结果应该是这样的:

b = "0O000RAN0000GE"
Run Code Online (Sandbox Code Playgroud)

什么是在Python中解决这个问题最好的方法?是否可以将索引绑定到每个替换?

非常感谢!海尔格

python string loops replace substitution

5
推荐指数
2
解决办法
335
查看次数

标签 统计

loops ×1

python ×1

replace ×1

string ×1

substitution ×1