Input Format
A single line of input contains the string .
Constraints
Output Format
Output the sorted string .

Hackerrank ginorts problem solution in python












Problem solution in python 2 programming language.

from __future__ import print_function

def func(x): 
    if x.isalpha():
        if x.isupper():
            return (ord(x)-ord('A'))
        else:
            return (ord(x)-ord('a'))-30
    else:
        if int(x) % 2 == 0:
            return 60+int(x)
        else:
            return 30+int(x)

s = raw_input()        
map(lambda x: print(x,end=''),(sorted(s,key = func)))

Second solution

from __future__ import print_function

upper = []
lower = []
even = []
odd = []

def separator(a):
    
    if a.isalpha():
        if a.isupper():
            upper.append(a)
        else:
            lower.append(a)
    else:
        if int(a)%2 == 0:
            even.append(a)
        else:
            odd.append(a)
    return 
    
map(separator,raw_input())       

upper.sort()
lower.sort()
even.sort()
odd.sort()

t = lower+upper+odd+even
map(lambda x: print(x,end=''),t)

Problem solution in python 3 programming language.

print(*sorted(input(), key=lambda c: (-ord(c) >> 5, c in '02468', c)), sep='')