HackerRank/해커랭크-sWAP cASE-python

cosmos·2021년 8월 11일
0
post-thumbnail

문제

풀이

  • You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.
  • Complete the swap_case function in the editor below.
  • swap_case has the following parameters:
  • string s: the string to modify
    Returns -> string: the modified string
  • Input Format : A single line containing a string s.

코드

# HackerRank, sWAP cASE, python3
def swap_case(s):
    result = [x.lower() if x.isupper() else x.upper() for x in s]
    return ''.join(result)

if __name__ == '__main__':
    word = str(input())
    
    print(swap_case(word))

결과

출처 && 깃허브

HackerRank
github

0개의 댓글