Out of curiosity, how would you reverse a string's case in Python? Make uppercase characters lowercase and lowercase characters uppercase.
Here's the function for the naive implementation.
#!/usr/bin/env python
def flip_case(input_string):
temp_list = list(input_string)
for index, character in enumerate(temp_list):
if character.islower():
temp_list[index] = character.upper()
else:
temp_list[index] = character.lower()
output_string = ''.join(temp_list)
return output_string
my_string = "AaBbCc"
my_string = flip_case(my_string)
print(my_string)
The output is:
aAbBcC
I'm thinking a smarter implementation would be to use a string's translate method. What do you think?