DEV Community

Discussion on: Daily Challenge #34 - WeIrD StRiNg CaSe

Collapse
 
hectorpascual profile image
Héctor Pascual

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))])