+ 4

string.Replace in python

how are the rules for "abbbbbbbba".replace("bbbbb","cccccc") what to do if the middle is to be replaced?

11th Nov 2017, 1:43 PM
Oma Falk
Oma Falk - avatar
7 Respuestas
+ 9
s="The dog is large small" ss=s.replace(s.split()[3],s.split()[3]+'ly') ss 'The dog is largely small' you can do like this
11th Nov 2017, 1:59 PM
MsJ
MsJ - avatar
+ 4
I don't understand!
11th Nov 2017, 1:54 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 4
@brains The string contains 7b's . How to call rhe statement replace, if the middle 5 b's are to be replaced?
11th Nov 2017, 3:22 PM
Oma Falk
Oma Falk - avatar
+ 4
I read the doc, but this case is not handled.
11th Nov 2017, 3:23 PM
Oma Falk
Oma Falk - avatar
+ 1
you can use an auxiliar list to save the values that has to be the sames,then replace the rest and finally concatenate. something like this: aux='a' new=replace('old','new') aux2='a' final=aux+new+aux2
11th Nov 2017, 8:53 PM
Ezequiel Gonzalez
Ezequiel Gonzalez - avatar
+ 1
yaaa
15th Nov 2017, 12:48 AM
aravinda