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
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
Comments
Leave a comment