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.
for i in S:
if i.isalpha() and i.islower():
v.append(i)
elif i.isalpha() and i.isupper():
u.append(i)
elif i.isnumeric():
t.append(i)
v=sorted(v)
u=sorted(u)
t=sorted(t,key=lambda x:(int(x)%2==0,int(x)))
k=v+u+t
print("".join(k))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
string = input() odd = '' even = '' lower = '' upper = '' for i in string: if i.isupper(): upper+=i elif i.islower(): lower+=i elif i.isdigit(): if int(i) % 2 == 0: even+=i else: odd +=i
print("" .join(sorted(lower))+"".join(sorted(upper))+"".join(sorted(odd))+"".join(sorted(even)))
Created a sort function instead of breaking up the types into separate strings. Same idea though.
S=input().strip() v,u,t=[],[],[]
for i in S: if i.isalpha() and i.islower(): v.append(i) elif i.isalpha() and i.isupper(): u.append(i) elif i.isnumeric(): t.append(i)
v=sorted(v) u=sorted(u) t=sorted(t,key=lambda x:(int(x)%2==0,int(x))) k=v+u+t print("".join(k))