Answer to Question #265976 in Python for binnu

Question #265976

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


1
Expert's answer
2021-11-15T00:30:42-0500
s = input()


ss = set()
d = dict()


mx = s.count(s[0])
mn = s.count(s[0])


mnc = s[0]
mxc = s[0]


for i in s:
    ss.add(i)


for i in ss:
    f = {i: s.count(i)}
    mx = max(mx, s.count(i))
    mn = min(mn, s.count(i))
    d.update(f)
for i in d:
    if d[i] == mn: 
        mnc = i
        break
for i in d:
    if d[i] == mx:
        mxc = i
        break


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