forked from ganeshkavhar/python-string-operations...
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharfreqcount.py
More file actions
41 lines (31 loc) · 939 Bytes
/
charfreqcount.py
File metadata and controls
41 lines (31 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Written in Python 3.
This program is all yours now! Have fun experimenting!!
This program accepts a sentence and prints the frequency of all the letters in the sentence.
teaches: creating functions, function calling, loops, bubble sort algorithm, lists (arrays), dictionary.
"""
def main():
sentence = input("\n\nEnter a sentence\n")
sentence = sentence.lower()
string = sentence.replace(" ","")
chars = []
for char in string:
chars.append(char)
alphad = {}
for i in range(0,len(chars)):
for j in range(0,len(chars)-1):
if ord(chars[j]) > ord(chars[j+1]):
chars[j+1] , chars[j]=chars[j],chars[j+1]
for i in range(0,len(chars)-1):
abet = chars[i]
count = 0
for j in chars:
if j == abet:
count += 1
alphad.update({abet:count})
print ("\n<!---FREQUENCY---!>\n")
for ch in alphad:
print (ch + " : "+str(alphad[ch]))
print ("\n\n")
main()
# written by @shreydan. github.com/shreydan