Monday, 31 October 2022

Task and Solution in Python - ginortS of HackerRank

 

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

ginortS1324

Solution 

import re

val = input()

lowercase = ''.join(sorted(re.findall("[a-z]",val)))
uppercase = ''.join(sorted(re.findall("[A-Z]",val)))
oddDigit = ''.join(sorted(re.findall("[1,3,5,7,9]",val)))
notOddDigit = ''.join(sorted(re.findall("[0,2,4,6,8]",val)))

print(lowercase+uppercase+oddDigit+notOddDigit)


Source : HackerRank

No comments:

Post a Comment