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 a7062df commit 01960e7Copy full SHA for 01960e7
general_problems/strings/count_unique_words.py
@@ -0,0 +1,20 @@
1
+import string
2
+import sys
3
+
4
5
+def count_unique_word():
6
+ words = {}
7
+ strip = string.whitespace + string.punctuation + string.digits + "\"'"
8
+ for filename in sys.argv[1:]:
9
+ with open(filename) as file:
10
+ for line in file:
11
+ for word in line.lower().split():
12
+ word = word.strip(strip)
13
+ if len(word) > 2:
14
+ words[word] = words.get(word,0) +1
15
16
+ for word in sorted(words):
17
+ print("'{0}' occurs {1} times.".format(word, words[word]))
18
19
+if __name__ == '__main__':
20
+ count_unique_word()
0 commit comments