Posts

Showing posts with the label ginorts

ginortS in Python - HackerRank solution

Solution for hackerRank problem ginortS in Python Problem : You are given a string S.  S contains alphanumeric characters only.  'SORTING' Your task is to sort the string S 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 S. Constraints 0 < len(S) < 1000 Output Format Output the sorted string S. Sample Input Sorting1234 Sample Output ginortS1324 Code : s = str(input()) Upper = [] lower = [] odd_no = [] even_no = [] for i in s:     if(i.isupper()):         Upper += [i]     if(i.islower()):         lower += [i]     if(i.isnumeric()):         if(int(i)%2 == 0):             even_no += [i]         else :             odd_no += [i] Upper.sort() lower.sort() odd_no.sort() even_no.sort() Upper = "".join(Upper) lower = "".join(lower) odd = "".join(odd_no) ev