Right-to-left string replace in Python?

后端 未结 7 708
轻奢々
轻奢々 2020-12-01 10:20

I want to do a string replace in Python, but only do the first instance going from right to left. In an ideal world I\'d have:

myStr = \"mississippi\"
print          


        
相关标签:
7条回答
  • 2020-12-01 10:57
    >>> myStr[::-1].replace("iss"[::-1], "XXX"[::-1], 1)[::-1]
    'missXXXippi'
    
    0 讨论(0)
提交回复
热议问题