GINSORT
ginortS
You are given a string .
contains alphanumeric characters only. Your task is to sort the string in the following manner:
- All sorted lowercase letters are ahead of uppercase letters.
- All sorted uppercase letters are ahead of digits.
- All sorted odd digits are ahead of sorted even digits.
Input Format
A single line of input contains the string .
Constraints
Output Format
Output the sorted string .
Sample Input
Sorting1234
Sample Output
ginortS1324CODE:a=input()
l=''
u=''
e_d=''
o_d=''
for i in a:
if i.isalpha() and i.islower():
l+=i
elif i.isalpha() and i.isupper():
u+=i
elif i.isdigit and int(i)%2==0:
e_d+=i
elif i.isdigit and int(i)%2!=0:
o_d+=i
l=''.join(sorted(l))
u=''.join(sorted(u))
e_d=''.join(sorted(e_d))
o_d=''.join(sorted(o_d))
print(l+u+o_d+e_d)
OTHER CODE:
def even(x):
if x.isdigit():
if int(x)%2 ==0:
return True
else:
return False
else: return True
print (*sorted(k,key = lambda x:(x.isdigit(),even(x),x.isupper(),x)),sep='')
else: return True
print (*sorted(k,key = lambda x:(x.isdigit(),even(x),x.isupper(),x)),sep='')
Comments
Post a Comment