Travis build: 189
This commit is contained in:
@ -1761,13 +1761,15 @@ byte_size('Hello World') # 11
|
||||
|
||||
Converts a string to camelcase.
|
||||
|
||||
Break the string into words and combine them capitalizing the first letter of each word, using a regexp, `title()` and `lower`.
|
||||
Use `re.sub()` to replace any `-`,`_` or ` ` (space) with a space, using the regexp `r"(_|-)+"`.
|
||||
Use `title()` to capitalize the first letter of each word convert the rest to lowercase.
|
||||
Finally, use `replace()` to remove spaces between words.
|
||||
|
||||
```py
|
||||
import re
|
||||
|
||||
def camel(s):
|
||||
s = re.sub(r"(\s|_|-)+", " ", s).title().replace(" ", "")
|
||||
s = re.sub(r"(_|-)+", " ", s).title().replace(" ", "")
|
||||
return s[0].lower() + s[1:]
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user