-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_neg_freqs_v3_counting.py
50 lines (38 loc) · 1.35 KB
/
extract_neg_freqs_v3_counting.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
# Counting the number of negative freq's
import re
import os
import numpy as np
import pdb
# None of the imports are required
# We only need a count
negatives = 0
# Previously I was not closing the file
# This closes it automagically
with open('neg_freqs_grabbing_more_decimals.txt', 'r') as f:
# print f
for line in f:
# No need for a regular expression here
if line.startswith("./"):
if negatives:
print 'len(negatives) = ', negatives, '\n'
negatives = 0
print line
# Used "else if" since both `startswith` can't be true
elif line.startswith("["):
# print 'line = ', line
# print 'type(line) = ', type(line)
# `line` is a <type 'str'>. We need to change if to list,
# in order to count. This requires 2 steps:
# 1st: Remove "[]''" from `line`:
target2 = line.translate(None, "[]'',")
# print 'target2 = ', target2
# 2nd: split that line target2
aux = target2.split()
# print 'aux = ', aux
# print 'type(aux) = ', type(aux)
# `aux` is now a <type 'list'>.
# print 'len(aux) = ', len(aux)
# negatives = negatives + len(aux)
negatives += len(aux) # more compact
if negatives:
print 'len(negatives) = ' , negatives