Answer to Question #283330 in Python for Uuu

Question #283330

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


1
Expert's answer
2021-12-28T10:03:23-0500
# Python 3.9.5

def get_most_less_char(test_str):
    all_freq = {}
    for i in test_str:
        if i in all_freq:
            all_freq[i] += 1
        else:
            all_freq[i] = 1
    res_max = max(all_freq, key=all_freq.get)
    res_min = min(all_freq, key=all_freq.get)
    return res_min, res_max

def main():
    strng = input('Enter sentence: ')
    res_min, res_max = get_most_less_char(strng)
    print("Original sentence: " + strng)
    strng = strng.replace(res_max, res_min)
    print("Special sentence: " + strng)

if __name__ == '__main__':
    main()

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