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
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
Comments
Leave a comment