sWAP cASE

  • + 0 comments

    I'll be checking out some of these other scripts for performance. My concept - I thought it'd be fun to build off of the list index in my loop. It works. ChatGPT claimed that this list-driven syntax will have better performance than string concatenation, e.g. the += letter.lower() syntax.

    def swap_case(s): newstring = list(s) # Create an empty string to store the new text

    for index in range(len(newstring)):
        if newstring[index].isupper():
           newstring[index]= newstring[index].lower()
        else: 
            newstring[index]= newstring[index].upper()
    return ''.join(newstring)  #Combining the separate characters back into a string
    

    if name == 'main': s = input() result = swap_case(s) print(result)