-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyDictionary.py
More file actions
37 lines (26 loc) · 936 Bytes
/
keyDictionary.py
File metadata and controls
37 lines (26 loc) · 936 Bytes
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
import csv
year = input("Enter year to query: ")
year = str(year)
Dictfilename = year + "keyDict.csv"
Readfilename = year + "keyword.csv"
with open(Dictfilename, 'wb') as csvfile:
resultwriter = csv.writer(csvfile, delimiter= ',' ,
quoting=csv.QUOTE_MINIMAL)
keyDictionary = {}
keyCount = 0
infile = open(Readfilename, "r")
for line in infile:
result = line.split(",")
keyword = result[0]
section = result[1]
if keyword in keyDictionary:
keyCount = keyDictionary[keyword]
keyCount = keyCount + 1
keyDictionary[keyword] = keyCount
else:
keyDictionary[keyword] = 1
#{keyword:keyCount}
# print(keyDictionary)
for key,value in keyDictionary.iteritems():
resultwriter.writerow([key, value])
# print(value, key)