-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenfordlivejournal.py
More file actions
64 lines (60 loc) · 1.78 KB
/
benfordlivejournal.py
File metadata and controls
64 lines (60 loc) · 1.78 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import re
DECIMAL_NUM = '123456789'
term = []
term2 = []
term3 = []
pat = re.compile('[(][)][*)][(*]')
def benford(dict_filename):
with open('livejournal.txt', 'r') as infile:
lines = infile.readlines()
for number in lines:
split_line = number.split()
for elmt in split_line:
elmt = re.sub(pat, '', elmt)
term.append(elmt)
for word in term:
word = word.strip('*)')
term2.append(word)
for num in term2:
num = num[:1]
term3.append(num)
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
seven = 0
eight = 0
nine = 0
for number in term3[6:]:
if number[0] == DECIMAL_NUM[0]:
one += 1
elif number[0] == DECIMAL_NUM[1]:
two += 1
elif number[0] == DECIMAL_NUM[2]:
three += 1
elif number[0] == DECIMAL_NUM[3]:
four += 1
elif number[0] == DECIMAL_NUM[4]:
five += 1
elif number[0] == DECIMAL_NUM[5]:
six += 1
elif number[0] == DECIMAL_NUM[6]:
seven += 1
elif number[0] == DECIMAL_NUM[7]:
eight += 1
elif number[0] == DECIMAL_NUM[8]:
nine += 1
print(one)
print(two)
print(three)
print(four)
print(five)
print(six)
print(seven)
print(eight)
print(nine)
print(term3[6:])
dict_filename = 'livejournal.txt'
benford(dict_filename)