I've been stuck on this problem for a while. I love CodeAcademy, but I've finished the courses I'm interested in so I've started using other sites to continue practicing. I still use CodeAcademy labs to run my code, but now that I'm running into problems, I need help and I'm not comfortable posting on the elitist StackOverflow (had a bad experience).
Basically, I can't figure out how to take out the white space between characters as I iterate over a string.
In the example below, I'm trying to iterate over a string and switch the case from upper to lower or vice versa. Right now my code prints out the right cases, but with a space between each character. I've tried looking up solutions on StackOverflow and I've seen people suggesting removing white space with "".join() or str.split() but I can't seem to figure it out. Any help would be great
def to_alternating_case(string): result = '' for x in string: if x.isupper(): print x.lower(), "".join(string) else: print x.upper(), "".join(string)
EDIT: This is how I edited my code that passed:
def to_alternating_case(string): result = '' for x in string: if x.isupper(): result += x.lower() else: result += x.upper() return result