Last active
October 5, 2020 16:41
-
-
Save kurzweil777/b1c8704558da46222c95400742acbe10 to your computer and use it in GitHub Desktop.
Exercise from CodeWars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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