Skip to content

Commit 01960e7

Browse files
committed
strip() example
1 parent a7062df commit 01960e7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)