-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonLab2.py
34 lines (28 loc) · 933 Bytes
/
PythonLab2.py
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
import json
import string
import argparse
import os
def main(inputString):
special_characters = ['!','#','$','%','&','?','.',',']
for i in special_characters:
inputString = inputString.replace(i,'')
all_lower = inputString.lower()
splitWords = all_lower.split(' ')
store_dict = {}
count = 1
for i in splitWords:
if i in store_dict:
count += 1
store_dict[i] = count
else:
count = 1
store_dict[i] = count
print(store_dict)
# Write the code to count the number of words here
# Remember to save the dictionary as a json file named "word-counts.json"
return None
if __name__ == "__main__":
parser = argparse.ArgumentParser("Word Counter")
parser.add_argument("-s","--string",type=str,required=True, help="Sentence to have the number of words counted")
args = parser.parse_args()
main(args.string)