Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Python » Python program » Frequancy of Character

Python program frequancy of characters in a string

# Author: CppBuzz.com
# This program find characters frequency in the given string
# Date: 22nd Aug 2020

def charFrequency(userInput):
    userInput = userInput.lower()  # covert string to lowercase
    dict = {}
    for char in userInput:
        keys = dict.keys()
        if char in keys:
            dict[char] += 1
            dict[char] = 1
    return dict

if __name__ == '__main__':
    userInput = str(input("Enter any string: "))

find frequancy of characters in any given string