Modernize Python 2 code to get ready for Python 3
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
#!/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))
|
||||
words = [x.lower() for x in re.split("[^a-zA-Z]+", open(sys.argv[1]).read()) if len(x) > 0 and x.lower() not in stops]
|
||||
unique_words = list(set(words))
|
||||
unique_words.sort(lambda x, y: cmp(words.count(y), words.count(x)))
|
||||
print "\n".join(["%s - %s" % (x, words.count(x)) for x in unique_words[:25]])
|
||||
unique_words.sort(key=lambda x: words.count(x), reverse=True)
|
||||
print("\n".join(["%s - %s" % (x, words.count(x)) for x in unique_words[:25]]))
|
||||
|
||||
Reference in New Issue
Block a user