Massive renaming!

This commit is contained in:
Crista Lopes
2019-08-12 14:38:16 -07:00
parent e6c1238a56
commit 61d5f74ad9
90 changed files with 0 additions and 0 deletions

13
04-monolith/README.md Normal file
View File

@@ -0,0 +1,13 @@
Style #3
==============================
Constraints:
- No abstractions
- No use of library functions
Possible names:
- Monolith
- Labyrinth
- Brain dump

49
04-monolith/tf-04.py Executable file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/env python
import sys, string
# the global list of [word, frequency] pairs
word_freqs = []
# the list of stop words
with open('../stop_words.txt') as f:
stop_words = f.read().split(',')
stop_words.extend(list(string.ascii_lowercase))
# iterate through the file one line at a time
for line in open(sys.argv[1]):
start_char = None
i = 0
for c in line:
if start_char == None:
if c.isalnum():
# We found the start of a word
start_char = i
else:
if not c.isalnum():
# We found the end of a word. Process it
found = False
word = line[start_char:i].lower()
# Ignore stop words
if word not in stop_words:
pair_index = 0
# Let's see if it already exists
for pair in word_freqs:
if word == pair[0]:
pair[1] += 1
found = True
break
pair_index += 1
if not found:
word_freqs.append([word, 1])
elif len(word_freqs) > 1:
# We may need to reorder
for n in reversed(range(pair_index)):
if word_freqs[pair_index][1] > word_freqs[n][1]:
# swap
word_freqs[n], word_freqs[pair_index] = word_freqs[pair_index], word_freqs[n]
pair_index = n
# Let's reset
start_char = None
i += 1
for tf in word_freqs[0:25]:
print(tf[0], ' - ', tf[1])