Trying to replace _(character) with just its Uppercase variant. For example:
hello_string_processing_in_python to helloStringProcessingInPython
Since string is immutable in Python, how can string substitution be done efficiently?
ss = 'hello_string_processing_in_python'
for i in re.finditer('_(\w)', ss):
????
You may try this,
>>> s = "hello_string_processing_in_python"
>>> re.sub(r'_([a-z])', lambda m: m.group(1).upper(), s)
'helloStringProcessingInPython'
No split or regex is needed and it also ensures that the first character is lowercase:
lower_camel_case = ss[0].lower() + ss.title()[1:].replace("_", "")
print(lower_camel_case)
helloStringProcessingInPython
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With