Skip to content

Commit

Permalink
Take filename argument from program arguments
Browse files Browse the repository at this point in the history
Previously, I had hard-coded this. This commit also makes it so that
the script can be executed from any current working directory and
(hopefully) makes it platform agnostic by using os.path.join to build
the path to the stop words file.
  • Loading branch information
bmistree committed May 21, 2016
1 parent a5e05c4 commit c94acde
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion 06-code-golf/tf-06-bm.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print (reduce(lambda string, tup: string + tup[0] + ' - ' + str(tup[1]) + '\n', sorted( filter(lambda tup: tup[0] not in open('../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 list(range(ord('a'), ord('z') + 1)) else letter, open('../pride-and-prejudice.txt').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()), {}).iteritems()), key=lambda tup: tup[1], reverse=True)[0:25], '')) # hole in one?

0 comments on commit c94acde

Please sign in to comment.