python codes for counting the occurrence of a letters in dictionary excluding digits

Solutions on MaxInterview for python codes for counting the occurrence of a letters in dictionary excluding digits by the best coders in the world

showing results for - "python codes for counting the occurrence of a letters in dictionary excluding digits"
Blessing
12 Feb 2018
1def count_letters(text):
2      result = {}
3      # Go through each letter in the text
4      for letter in text:
5        # Check if the letter needs to be counted or not
6        if letter not in result:
7          result[letter.lower()] = 1
8        # Add or increment the value in the dictionary
9        else:
10          result[letter.lower()] += 1
11      return result
12
13    print(count_letters("AaBbCc"))
14    # Should be {'a': 2, 'b': 2, 'c': 2}
15
16    print(count_letters("Math is fun! 2+2=4"))
17    # Should be {'m': 1, 'a': 1, 't': 1, 'h': 1, 'i': 1, 's': 1, 'f': 1, 'u': 1, 'n': 1}
18
19    print(count_letters("This is a sentence."))
20    # Should be {'t': 2, 'h': 1, 'i': 2, 's': 3, 'a': 1, 'e': 3, 'n': 2, 'c': 1}
21
queries leading to this page
write a python program to count the number of characters 28character frequency 29 in a stringmake dictionary of count of letters in wordscount character frequency in string pythonpython to count letter frequency in a sentencecount frequency of string in python a to zfrequency of a character in a string pythonhow to count the frequency of characters in a string in pythonpython dictionary counting letterspython letter frequencypython count letters of alphabetpython program using add 28 29 method to find histogram to count the number of times each letter apppears in a word and in sentencepython count letter frequency in stringpython count letters in the aphabetcount frequency of characters in string pythonusing counter collections in python to count number of characters in stringcounting frequency of characters in a string pythonpython count character frequency in stringpython string freqeuncydict of char counts to string pythoncount array of all alphabets in pythoncount occurrences of character in string python using dictionarynumber of all character in string pythonoverall disturbution of string pythonpython program to find frequency of characters in a stringfrequency of characters in a string pythoncount occurrences of each character in string pythonwrite a python function and create a list consisted of the number of occurence of letter 3a a python program for polymorphism with function to find histogram to count the number of times each letter apppears in a word and in sentencepython count frequency of characters in stringpython program to give a sentence and a character and counts the frequency of the given characterpython frequency of character in stringfreequency in a string pythonhow to find the frequency of a string in python adn store them in dictionaypython codes for counting the occurrence of a letters in dictionary excluding digits