String Sorting

This is the problem, I have solved Today,
this question is asked in  the  Infosys  INFYQT Certification exam.

Question:

Arrange the string based on the number in the string

Input:

bc43,fg23hg,gh22,hjjk44

Output:

gh22,fg23hg,hjjk43,hjjk43

Program:

python3
s=input("").split(',')
print(s)
l=[]
d={}
r=[]
for i in s:
    a=' '
    for j in i:
        if(not ord(j)>=ord('a') and ord(j)<=ord('z') or ord(j)>=ord('A') and ord(j)<=ord('Z')):
            a=str(a)+str(j)
    l.append(int(a))
#print(l)

for i in range(len(l)):
    d[l[i]]=s[i]
#print(d)
l.sort()
#print(l)
for i in l:
    r.append(d[i])
   
#print(r)
b=''
for i in r:
    b=str(b)+i+','
print(b)
   

 

Comments

  1. super...how to this....not understand.....explain me

    ReplyDelete

Post a Comment

Popular posts from this blog

Software Freedom Day 2020

gobuster

Addition Game