forked from fenyx-it-academy/Class8-Python-Module-Week3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek2_hmwrk_2.py
More file actions
21 lines (18 loc) · 747 Bytes
/
Week2_hmwrk_2.py
File metadata and controls
21 lines (18 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
text = input("Enter a text: ")
# creating an empty dictionary to store letter counts
letter_counts = {}
# For loop and iterate through each letter in the text
for letter in text:
# ignore spaces and convert letter to lowercase
if letter != ' ':
letter = letter.lower()
# if the letter is already in the dictionary, increase the counting
if letter in letter_counts:
letter_counts[letter] += 1
# or else, add the letter to the dictionary with a count of 1
else:
letter_counts[letter] = 1
# items() for getting the elemnets as pairs, sort() for getting the alphabetic order
letter_counts_list = list(letter_counts.items())
letter_counts_list.sort()
print(letter_counts_list)