In this HackerRank Any or All problem solution You are given a string S. S contains alphanumeric characters only. Your task is to sort the string S in the following manner:

  1. All sorted lowercase letters are ahead of uppercase letters.
  2. All sorted uppercase letters are ahead of digits.
  3. All sorted odd digits are ahead of sorted even digits.

HackerRank ginortS in python problem solution

HackerRank ginortS in python problem solution

def key(thing):
    if thing.islower():
        return ord(thing) - 97
    if thing.isdigit():
        it = int(thing)
        return it + 100 if it % 2 == 1 else it + 120
    return ord(thing)

S = raw_input()
print reduce(lambda x, y: x + y, sorted(S, key=key))