Computer Science, asked by bandarudivyasree123, 2 months ago

E DESCRIPTION
D DISCUSS
Rearrange Numbers in String
Given a string, 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.
Input
N
The input will be a single line containing a string.​

Answers

Answered by mohan1140bhonu
0

Answer:

import re

import pdb

string = "Exam23 is Not EndBy35 tomorrow98"

count = 0

digits = []

for match in re.finditer('[0-9]+',string):

count += 1

digits.append(int(match.group()))

digits.sort(reverse = True)

output = ""

i = 0

words_list = string.split()

for index in range(len(words_list)):

# pdb.set_trace()

if re.findall('[0-9]+',words_list[index]):

 for match in re.finditer('[0-9]+',words_list[index]):

  #pdb.set_trace()

  output += words_list[index].replace(match.group(),str(digits[i]))

 

  output += " "

  #output = output + word

 i += 1

else:

 output += words_list[index]

 output += " "

print(output)

Explanation:

Similar questions