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