sWAP cASE

  • + 1 comment

    Problem itself is pretty straight forward you are given a string you gotta return the upper case letter if it has a lower case letter and lower case letter to upper case 1. Make an empty string 2. check if the current i'th letter is even a letter or it's some number it's not letter and leave it and append it as it's into the list , if it's a letter then simply check the letter is upper or lower if it's lower then make it upper if it's upper then make it lower 3. Return the list as a string format because the problem seeks a string def swap_case(s): s1 = [] for item in s: if item.isalpha(): if item.isupper(): s1.append(item.lower()) else: s1.append(item.upper()) else: s1.append(item) return ''.join(s1)

    1. Code
    • + 0 comments

      s1 = [] for item in s: if item.isalpha(): if item.isupper(): s1.append(item.lower()) else: s1.append(item.upper()) else: s1.append(item) return ''.join(s1)