Finally rewrote the code for Python3!

This commit is contained in:
Crista Lopes
2018-12-13 19:57:17 -08:00
parent 4449f0b7ba
commit ed8c3cabaa
47 changed files with 70 additions and 115 deletions

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import re, string, sys
stops = set(open("../stop_words.txt").read().split(",") + list(string.ascii_lowercase))

View File

@@ -1,3 +1,2 @@
from __future__ import print_function
from functools import reduce
print (reduce(lambda string, tup: string + tup[0] + ' - ' + str(tup[1]) + '\n', sorted( filter(lambda tup: tup[0] not in open(__import__('os').path.join(__import__('os').path.dirname(__file__), '..', 'stop_words.txt')).read().lower().split(','), reduce(lambda word_dict, word: word_dict if (word_dict.__setitem__(word, word_dict.get(word, 0) + 1) if True else None) else word_dict, filter(lambda word: len(word) > 1, (''.join(map(lambda letter: ' ' if ord(letter) not in set(range(ord('a'), ord('z') + 1)) else letter, open(__import__('sys').argv[1]).read().lower()))).split()), {}).iteritems()), key=lambda tup: tup[1], reverse=True)[0:25], '')) # hole in one?
print (reduce(lambda string, tup: string + tup[0] + ' - ' + str(tup[1]) + '\n', sorted( filter(lambda tup: tup[0] not in open(__import__('os').path.join(__import__('os').path.dirname(__file__), '..', 'stop_words.txt')).read().lower().split(','), reduce(lambda word_dict, word: word_dict if (word_dict.__setitem__(word, word_dict.get(word, 0) + 1) if True else None) else word_dict, filter(lambda word: len(word) > 1, (''.join(map(lambda letter: ' ' if ord(letter) not in set(range(ord('a'), ord('z') + 1)) else letter, open(__import__('sys').argv[1]).read().lower()))).split()), {}).items()), key=lambda tup: tup[1], reverse=True)[0:25], '')) # hole in one?

View File

@@ -1,8 +1,6 @@
#!/usr/bin/env python
# My golf score is slightly lower!
# Best wishes, Peter Norvig
from __future__ import print_function
import re, sys, collections
stopwords = set(open('../stop_words.txt').read().split(','))

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import heapq, re, sys
words = re.findall("[a-z]{2,}", open(sys.argv[1]).read().lower())