def to_camel_case(text): split_chars = " -" for i in split_chars: text = text.replace(i,'_') text = text.split('_') for i in range(1,len(text)): text[i] = text[i].title() return ''.join(text)
def to_camel_case(text: str):split_chars = "-_"# loop over each character abovefor split_char in split_chars:split_parts = text.split(split_char)# skip if there was nothing to split onif len(split_parts) == 1:continueparts = []# break up the string in to it's partsfor i, item in enumerate(split_parts):# save the first part but don't change the case of the first letterif i == 0:parts.append(item)continueparts.append(f"{item[0].upper()}{item[1:]}")# join the parts and overwrite the text variable for the next looptext = "".join(parts)return text- def to_camel_case(text):
- split_chars = " -"
- for i in split_chars:
- text = text.replace(i,'_')
- text = text.split('_')
- for i in range(1,len(text)):
- text[i] = text[i].title()
- return ''.join(text)