We're a place where coders share, stay up-to-date and grow their careers.
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))])
Python with a function :
One liner with list comprehension :