Skip to content

Instantly share code, notes, and snippets.

@kurzweil777
Last active October 5, 2020 16:41
Show Gist options
  • Save kurzweil777/b1c8704558da46222c95400742acbe10 to your computer and use it in GitHub Desktop.
Save kurzweil777/b1c8704558da46222c95400742acbe10 to your computer and use it in GitHub Desktop.
Exercise from CodeWars
def kebabize(string):
"""Modify the kebabize function so that it converts a camel case string into a kebab case."""
for letter in string:
if letter.isupper():
string = string.replace(letter, "-" + letter.lower())
elif letter.isdigit():
string = string.replace(letter, "")
return string.lstrip("-")
kebabize('myCamelCasedString') # my-camel-cased-string
kebabize('myCamelHas3Humps') # my-camel-has-humps
kebabize('SOS') # s-o-s
kebabize('42') # ''
kebabize('CodeWars') # code-wars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment