toWeirdCase=lambdas:''.join([c.lower()ifi%2elsec.upper()fori,cinenumerate(s)])print(toWeirdCase('String'))#=> StRiNg
print(toWeirdCase('Weird string case'))#=> WeIrD StRiNg cAsE
EDIT @dance2die
pointed out in this comment that the multi-word example in the post seems to suggest that each word should be considered and cased separately, rather than the whole string. In that case, this becomes a bit more interesting.
Here's a simple modification to account only for spaces separating words:
toWeirdCase=lambdas:' '.join([wordToWeirdCase(w)forwins.split(' ')])wordToWeirdCase=lambdas:''.join([c.lower()ifi%2elsec.upper()fori,cinenumerate(s)])print(toWeirdCase('String'))#=> StRiNg
print(toWeirdCase('Weird string case'))#=> WeIrD StRiNg CaSe
But this could get a lot more complex if we need to account for things like punctuation and other whitespace characters.
As one last example, here's one that handles alternative whitespace characters using regular expressions:
Python solution:
EDIT
@dance2die pointed out in this comment that the multi-word example in the post seems to suggest that each word should be considered and cased separately, rather than the whole string. In that case, this becomes a bit more interesting.
Here's a simple modification to account only for spaces separating words:
But this could get a lot more complex if we need to account for things like punctuation and other whitespace characters.
As one last example, here's one that handles alternative whitespace characters using regular expressions: