forked from vaibhav-jain18/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalphabet.py
More file actions
27 lines (21 loc) · 700 Bytes
/
alphabet.py
File metadata and controls
27 lines (21 loc) · 700 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
import urllib.request
import string
dictionary = (
"https://raw.githubusercontent.com/dwyl/ \
english-words/master/words_alpha.txt"
)
alphabet = {letter: 0 for letter in string.ascii_lowercase}
total_amount = 0
with urllib.request.urlopen(dictionary) as req:
for line in req:
dec_line = line.decode("UTF-8").strip().lower()
for letter in dec_line:
alphabet[letter] += 1
total_amount += len(line)
for letter in alphabet:
print(
f"{letter.upper()}:\t{alphabet[letter]}\
t{round(alphabet[letter]/total_amount*100, 2)}%"
)
print("--------------------------")
print(f"Total amount: {total_amount}")