Answer to Question #280490 in Python for saivarun

Question #280490

re-arange string in python



input.

i am 11years 8 months 5 days old


output.

i am 5 years 8 months 11 days old




1
Expert's answer
2021-12-17T06:57:19-0500
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()))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS