Answer to Question #283767 in Python for sai

Question #283767

anil is given a sentence as he tries to make a sentence special a sentence can be made special by swapping the character with high frequency with the character having low frequency in the sentence help anil by transforming the sentence into. a special sentence in python.


swap most frequent letter with least given a sentence, swap the occurrences of the most frequenti with the least frequent letter and vice-versa. submisdong note: • consider upper and lower case letters as different . if there are multiple letters with the same frequency, choose the lower case letter that comes earliest in dictionary order o if letters like x and b have same frequency consider x o if letters like x and b have same frequency consider b.


Input: Python is a programming language


Output should be: Python is e progremming lenguega

1
Expert's answer
2021-12-31T01:41:55-0500
s = input()


mn, mx = s.count(s[0]), s.count(s[0])
mnc, mxc = 0, 0


for i in range(len(s)):
    if s.count(s[i]) > mx and s[i]!=' ':
        mx = s.count(s[i])
        mxc = i
    if s.count(s[i]) < mn and s[i]!=' ':
        mn = s.count(s[i])
        mnc = i


s1 = []
ss = []
for i in s:
    s1.append(i)
    ss.append(i)


ss[mnc] = s1[mxc]
ss[mxc] = s1[mnc]
print(''.join(ss))





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