re-arange string in python
input.
i am 11years 8 months 5 days old
output.
i am 5 years 8 months 11 days old
def RearrangeNumbers(source):
tmp0=source.split()
int_l=[]
for j,i in enumerate(tmp0):
try:
tmp0[j]=int(i)
int_l.append(int(i))
except ValueError:
pass
int_l.sort()
for j,i in enumerate(tmp0):
if isinstance(i,int):
tmp0[j]=str(int_l[0])
int_l.pop(0)
return ' '.join(tmp0)
print(RearrangeNumbers(input()))
Comments
Leave a comment