-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwords.py
More file actions
49 lines (40 loc) · 1.02 KB
/
Copy pathwords.py
File metadata and controls
49 lines (40 loc) · 1.02 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Get a file from the web:
http://icarus.cs.weber.edu/~hvalle/hafb/words.txt
Task 1: Count number of words in document
"""
from urllib.request import urlopen
def fetch_words(filename):
"""
Count words in url file
:param filename: url to file
:return: a list with the items
"""
count = 0
data = [] # empty list
with urlopen(filename) as story:
for line in story:
words = line.decode('utf-8').split() # split with space as separator
# print(words)
for word in words:
data.append(word)
return data
def print_items(items):
"""
Print elements of the collection
:param items: A collections of objects
:return: nothing
"""
for item in items:
print(item)
def main():
"""
Test function for words library
:return: nothing
"""
file = "http://icarus.cs.weber.edu/~hvalle/hafb/words.txt"
words = fetch_words(file)
print_items(words)
if __name__ == '__main__':
main()
exit(0)