We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
if name == "main":
intput_ = input()
evenumbers = sorted([ ch for ch in intput_ if ch.isdigit() and int(ch)%2==0])
oddnumbers = sorted([ ch for ch in intput_ if ch.isdigit() and int(ch)%2!=0])
capital = sorted([ch for ch in intput_ if ch.isupper()])
letters = sorted([ch for ch in intput_ if ch.isalpha() and ch.islower()])
final = "".join(letters)+"".join(capital)+"".join(oddnumbers)+"".join(evenumbers)
print(final)
string = input()
li = []
l1= []
l2 = []
l3 = []
for i in string:
if i.islower() == True:
li.append(i)
li.sort()
for i in string:
if i.isupper()==True:
l1.append(i)
l1.sort()
for i in string:
if i.isdigit() == True:
if float(i)%2 != 0:
l2.append(i)
l2.sort()
for i in string:
if i.isdigit() == True:
if float(i)%2 == 0:
l3.append(i)
l3.sort()
print(l2,l3)
last = (li+l1+l2+l3)
final = ''.join(last)
print(final)
word = input()
lower_letters = sorted([char for char in word if char.islower()])
upper_letters = sorted([char for char in word if char.isupper()])
odd_digits = sorted([num for num in word if not num.isalpha() and int(num)%2 != 0])
even_digits = sorted([num for num in word if not num.isalpha() and int(num)%2 == 0])
if name == "main": intput_ = input() evenumbers = sorted([ ch for ch in intput_ if ch.isdigit() and int(ch)%2==0]) oddnumbers = sorted([ ch for ch in intput_ if ch.isdigit() and int(ch)%2!=0]) capital = sorted([ch for ch in intput_ if ch.isupper()]) letters = sorted([ch for ch in intput_ if ch.isalpha() and ch.islower()]) final = "".join(letters)+"".join(capital)+"".join(oddnumbers)+"".join(evenumbers) print(final)
Here is HackerRank ginortS in Python solution - https://programmingoneonone.com/hackerrank-ginorts-problem-solution-in-python.html
string = input() li = [] l1= [] l2 = [] l3 = [] for i in string: if i.islower() == True: li.append(i) li.sort() for i in string: if i.isupper()==True: l1.append(i) l1.sort() for i in string: if i.isdigit() == True: if float(i)%2 != 0: l2.append(i) l2.sort() for i in string: if i.isdigit() == True: if float(i)%2 == 0: l3.append(i) l3.sort()
print(l2,l3)
last = (li+l1+l2+l3) final = ''.join(last) print(final)
Easy and simplet to understand code.
word = input() lower_letters = sorted([char for char in word if char.islower()]) upper_letters = sorted([char for char in word if char.isupper()]) odd_digits = sorted([num for num in word if not num.isalpha() and int(num)%2 != 0]) even_digits = sorted([num for num in word if not num.isalpha() and int(num)%2 == 0])
sorted_word = ''.join(lower_letters + upper_letters + odd_digits + even_digits)
print(sorted_word)