Q:

Write a Python program to count most and least common characters in a given string.

0

Write a Python program to count most and least common characters in a given string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

from collections import Counter 
def max_least_char(str1):
    temp = Counter(str1) 
    max_char = max(temp, key = temp.get)
    min_char = min(temp, key = temp.get)
    return (max_char, min_char)

str1 = "hello world"
print ("Original string: ")
print(str1)
result = max_least_char(str1)
print("\nMost common character of the said string:",result[0])
print("Least common character of the said string:",result[1])

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now