forked from imtiazahmad007/PythonCourse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassignment_01.py
79 lines (30 loc) · 1009 Bytes
/
assignment_01.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Assignment 1:
import sys
import os
import re
# directory_containing_files = "/Users/imtiazahmad/PycharmProjects/Assignments/Section_06/project_files" #sys.argv[1]
# words_to_aggregate = ["hello", "Peter", "computer"] #sys.argv[2:]
directory_containing_files = sys.argv[1]
words_to_aggregate = sys.argv[2:]
# Expected Output:
# {"there": n, "Michael": n, "running": n}
# Your Code Below:
#Solution:
# words_and_counts = {}
#
# for word in words_to_aggregate:
# count = 0
# for path, folder_names, file_names in os.walk(directory_containing_files):
# for file_name in file_names:
# file = os.path.join(path, file_name)
# with open(file, "r") as a_file:
# for line in a_file:
# if re.search(word, line):
# word_list = re.findall(word, line)
# count += len(word_list)
#
# words_and_counts[word] = count
#
#
#
# print(words_and_counts)