Answer to Question #226334 in Python for Reclimet

Question #226334

Rearrange Numbers in String

In this Python question they were given sample input and output when i did code for this question the sample input and output were came but they had some hidden test cases that hidden test cases are getting failed please give me the code related to question


The above Url contains Rearrange Numbers in String Question and explanation and sample input and output

https://drive.google.com/file/d/1Nx1CiQMNCMz4QectPcIYjnpyTYmQTqD6/view?usp=sharing


The above Url contains the code of Rearrange Numbers in String that i was tried

https://drive.google.com/file/d/14Lmk0_M7dKQuCdWDnFYKssJPZom4bldD/view?usp=sharing


1
Expert's answer
2021-08-16T01:06:23-0400



def IsNum(s):
    try:
        int(s)
        return True
    except ValueError:
        return False



s = input()
words = s.split()
numbers = []
for x in words:
    if IsNum(x):
        numbers.append(int(x))
if len(numbers) < 2:
    print(s)
numbers.sort(reverse=True)
result = ''
for x in words:
    if IsNum(x):
        result += str(numbers[0])
        numbers = numbers[1:]
    else:
        result += x
    result += ' '
print(result[:-1])

I am 5 years and 11 months
I am 11 years and 5 months


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