试图用它的大写变体替换_(字符).例如:
hello_string_processing_in_python to helloStringProcessingInPython
Run Code Online (Sandbox Code Playgroud)
由于字符串在Python中是不可变的,如何有效地完成字符串替换?
ss = 'hello_string_processing_in_python'
for i in re.finditer('_(\w)', ss):
????
Run Code Online (Sandbox Code Playgroud)
你可以试试这个,
>>> s = "hello_string_processing_in_python"
>>> re.sub(r'_([a-z])', lambda m: m.group(1).upper(), s)
'helloStringProcessingInPython'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
677 次 |
| 最近记录: |