Answer to Question #292073 in Python for Reorder the string

Question #292073

reorder the string.eren wants to modify a string.the string can contain only positive integers.he wants to change the string in such a way that the smaller numbers should appear before the bigger numbers.given a string write a program to help eren to modify the string

1
Expert's answer
2022-02-02T08:19:51-0500
list1 = []
list2 = []
list3 = []
j = 0
string = ''
input1 = input()
for i in input1:
    if i.isdigit() == True:
        list1.append(i)
        list2.append(input1.index(i))
zp = list(zip(list1,list2))
zp.sort()
for i in zp:
    list3.append(i[0])
for i in input1:
    if i.isdigit() == True:
        string = string + list3[j]   
        j = j+1
    else:
        string = string + i

string
'my124'

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