Number Arrangement
write a program to re-arrange all the numbers appearing in the string in decreasing order.
Note: There will not be any negative numbers or numbers with decimal part.
The input is a string containing the actual sentence.
The output is a string containing the modified sentence as mentioned above.
For example, if the actual sentence is It is a 3days 4nights holiday trip.
The numbers in the sentence are 3 and 4.After arranging them in the decreasing order, the output looks like It is a 4days 3nights holiday trip.
Sample Input1
It is a 3days 4nights holiday trip
Sample Output1
It is a 4days 3nights holiday trip
import re
input1 = input('')
numbers = tuple(sorted(map(int, re.findall(r'([\d]+)', input1)), reverse = True))
res = re.sub(r'([\d]+)', '%S', input1)
print(res % numbers)
Comments
Leave a comment