Skip to content

Commit 1fe759a

Browse files
Merge pull request geekcomputers#76 from walidmujahid/master
Updates for CountMillionCharacter.py
2 parents 3e08069 + c0c32ae commit 1fe759a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

CountMillionCharacters-2.0.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Get the number of each character in any given text.
2+
3+
Inputs:
4+
A txt file -- You will be asked for an input file. Simply input the name
5+
of the txt file in which you have the desired text.
6+
7+
"""
8+
9+
import pprint
10+
import collections
11+
12+
13+
def main():
14+
15+
file_input = input('File Name: ')
16+
17+
with open(file_input, 'r') as info:
18+
count = collections.Counter(info.read().upper())
19+
20+
value = pprint.pformat(count)
21+
print(value)
22+
23+
if __name__ == "__main__":
24+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pprint
2+
3+
inputFile = input('File Name: ')
4+
5+
count = { }
6+
with open(inputFile, 'r') as info:
7+
readFile = info.read()
8+
for character in readFile.upper():
9+
count.setdefault(character, 0)
10+
count[character] = count[character]+1
11+
12+
value = pprint.pformat(count)
13+
print(value)

0 commit comments

Comments
 (0)