Changing multiple characters by other characters in a string

后端 未结 3 1307
醉话见心
醉话见心 2021-01-13 07:13

I\'m trying to manipulate a string.

After extracting all the vowels from a string, I want to replace all the \'v\' with \'b\' and all the \'b\' with \'v\' from the

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 07:56

    You should use intermediate replacement to get proper result in python:

    s2.replace('b',' ')
    s2.replace('v','b')
    s2.replace(' ','v')
    

    In other words steps are following

    1. Replace b to ' ' space
    2. Replace 'v' to 'b'
    3. Replace ' ' space (that was your b character) to 'v'

    Good luck!

提交回复
热议问题