HACKER RANK Python Strings Challenges - sWAP cASE Solution,'Py'

Python Strings Challenges - sWAP cASE Solution

Problem Statement:
You are given a string S. Your task is to swap case, i.e., convert all lower case letters to upper case and vice versa.
Example :
Www.HackerRank.com → wWW.hACKERrANK.COM
Pythonist 2 → pYTHONIST 2
Input Format
Single line containing, String S.
Constraints
0<len(S)1000
Output Format
Print the modified string S.
Sample Input
HackerRank.com presents "Pythonist 2".
Sample Output
hACKERrANK.COM PRESENTS "pYTHONIST 2".

Solution:


import sys
if sys.version_info[0]>=3: raw_input=input
print(''.join(chr(ord(c)^32) if 'a'<=c<='z' or 'A'<=c<='Z' else c for c in raw_input()))

Thanks for Visiting, Hope this helps you....

Copyright © 2015 HackerRank.
All Rights Reserved

Comments

Popular Posts