Python with a function :
def to_weird_case(string): weird_string = '' i = 0 for c in string.lower(): if i%2: weird_string += c else: weird_string += c.upper() i += 1 return weird_string
One liner with list comprehension :
weird_case = ''.join([string[i].lower() if i%2 else string[i].capitalize() for i in range(0,len(string))])
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python with a function :
One liner with list comprehension :