We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9d29262 commit 1d627fdCopy full SHA for 1d627fd
word_count.py
@@ -0,0 +1,28 @@
1
+#!/usr/local/bin/python3
2
+
3
+import os
4
+import sys
5
+import pprint
6
7
+def everyWordCount(filename):
8
+ """
9
+ This function takes filename as one of the arguments from
10
+ the command line and prints count of each word in that
11
+ file.
12
13
+ # count of every word is stored in the dictionary
14
+ word_dict = {}
15
+ f = open(filename, "r")
16
+ for line in f:
17
+ word_list = line.split()
18
+ for word in word_list:
19
+ if word in word_dict.keys():
20
+ word_dict[word] += 1
21
+ else:
22
+ word_dict[word] = 1
23
+ return word_dict
24
25
26
+# filename is given from command line as the first arugument
27
+filename = sys.argv[1]
28
+pprint.pprint(everyWordCount(filename))
0 commit comments