forked from fenyx-it-academy/Class7-Python-Module-Week2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShatha_W2_Q2.py
More file actions
19 lines (18 loc) · 858 Bytes
/
Shatha_W2_Q2.py
File metadata and controls
19 lines (18 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""
Write a code snippet that inputs a sentence from the user, then uses a dictionary to summarize the number of occurrences of each letter. Ignore case, ignore blanks and assume the user does not enter any punctuation. Display a two-column table of the letters and their counts with the letters in sorted order.
```
Example
Input >>> "This is a sample text with several words This is more sample text with some different words"
Output >>>
[('a', 4), ('d', 3), ('e', 10), ('f', 2), ('h', 4), ('i', 7), ('l', 3), ('m', 4), ('n', 1), ('o', 4), ('p', 2), ('r', 5), ('s', 10), ('t', 9), ('v', 1), ('w', 4), ('x', 2)]
```"""
occ = {}
str = input('Enter a sentence to count the occurrences of each letter ')
str1 = str.replace(" ", "")
str2 = sorted(str1)
#print (str2)
for i in str2:
#print(str2.count(i))
occ[i] = str2.count(i)
#x = list(occ)
print(occ)