We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3b24556 commit e80dea9Copy full SHA for e80dea9
Chapter 12/Problem12_17.py
@@ -6,4 +6,35 @@
6
import re
7
import sqlite3
8
9
+def frequent(textfile):
10
+
11
+ arquivo = open(textfile)
12
+ content = arquivo.read()
13
+ arquivo.close()
14
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
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