Ad
Code
Diff
  • 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 above
    • for split_char in split_chars:
    • split_parts = text.split(split_char)
    • # skip if there was nothing to split on
    • if len(split_parts) == 1:
    • continue
    • parts = []
    • # break up the string in to it's parts
    • for i, item in enumerate(split_parts):
    • # save the first part but don't change the case of the first letter
    • if i == 0:
    • parts.append(item)
    • continue
    • parts.append(f"{item[0].upper()}{item[1:]}")
    • # join the parts and overwrite the text variable for the next loop
    • text = "".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)
Code
Diff
  • power = lambda num, pow: num**pow
    • power = pow
    • power = lambda num, pow: num**pow