"HR파이썬 sWAP cASE"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
10번째 줄: 10번째 줄:


{{소스헤더|풀이 1}}
{{소스헤더|풀이 1}}
<source lang='python'>
<syntaxhighlight lang='python'>
def swap_case(s):
def swap_case(s):
     return ''.join(map(lambda x: x.lower() if x.isupper() else x.upper(),s))
     return ''.join(map(lambda x: x.lower() if x.isupper() else x.upper(),s))
  </source>
  </syntaxhighlight>
{{소스헤더|풀이 2}}
{{소스헤더|풀이 2}}
<source lang='python'>
<syntaxhighlight lang='python'>
def swap_case(s):
def swap_case(s):
     def change_case(c):
     def change_case(c):
21번째 줄: 21번째 줄:
         return c.upper()
         return c.upper()
     return ''.join(map(change_case,s))
     return ''.join(map(change_case,s))
   </source>
   </syntaxhighlight>
{{소스헤더|하단}}
{{소스헤더|하단}}
<source lang='python'>
<syntaxhighlight lang='python'>
if __name__ == '__main__':
if __name__ == '__main__':
     s = input()
     s = input()
     result = swap_case(s)
     result = swap_case(s)
     print(result)
     print(result)
</source>
</syntaxhighlight>

2021년 7월 31일 (토) 10:53 기준 최신판

개요[ | ]

HR파이썬 sWAP cASE
해커랭크 Python
# 문제 비고
HR파이썬 Strings e
14 HR파이썬 sWAP cASE
15 HR파이썬 String Split and Join
16 HR파이썬 What's Your Name?
17 HR파이썬 Mutations
18 HR파이썬 Find a string
19 HR파이썬 String Validators
20 HR파이썬 Text Alignment
21 HR파이썬 Text Wrap
22 HR파이썬 Designer Door Mat
23 HR파이썬 String Formatting
24 HR파이썬 Alphabet Rangoli
25 HR파이썬 Capitalize!
26 HR파이썬 The Minion Game
27 HR파이썬 Merge the Tools!

풀이 1
def swap_case(s):
    return ''.join(map(lambda x: x.lower() if x.isupper() else x.upper(),s))
풀이 2
def swap_case(s):
    def change_case(c):
        if c.isupper(): return c.lower()
        return c.upper()
    return ''.join(map(change_case,s))
하단
if __name__ == '__main__':
    s = input()
    result = swap_case(s)
    print(result)
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}