Skip to content

Commit e80dea9

Browse files
committed
Did nother problem
1 parent 3b24556 commit e80dea9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Chapter 12/Problem12_17.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,35 @@
66
import re
77
import sqlite3
88

9+
def frequent(textfile):
10+
11+
arquivo = open(textfile)
12+
content = arquivo.read()
13+
arquivo.close()
914

15+
listwords = re.findall('[a-zA-Z]*', content)
16+
17+
contdict = dict()
18+
19+
for word in listwords:
20+
if word == '':
21+
pass
22+
else:
23+
if word not in contdict.keys():
24+
contdict[word] = 1
25+
else:
26+
contdict[word] += 1
27+
28+
listfreq = []
29+
30+
for key in contdict.keys():
31+
listfreq.append((key, contdict[key]))
32+
33+
con = sqlite3.connect('frequencydatabase.db')
34+
cur = con.cursor()
35+
36+
cur.execute("CREATE TABLE Wordcounts(Word, Freq)")
37+
cur.executemany("INSERT INTO Wordcounts VALUES(?, ?)", listfreq)
38+
39+
con.commit()
40+
con.close()

0 commit comments

Comments
 (0)