Created
March 31, 2013 16:32
-
-
Save anonymous/5281189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
a = open('gs2.txt') | |
b = a.read() | |
a.close() | |
b = b.decode('utf-8') | |
c = b.split() | |
thelist = [] | |
print "Starting find at", str(datetime.now()) | |
for word in c: | |
didfind = False | |
for entry in thelist: | |
if word in entry: | |
thelist[thelist.index(entry)][1] += 1 | |
didfind = True | |
if didfind == False: | |
thelist.append([word, 1]) | |
print "Finished find at", str(datetime.now()) | |
final = sorted(thelist, key=lambda word: word[1]) | |
final.reverse() | |
with open('output.txt', 'w') as d: | |
for item in final: | |
d.write(str(item[0].encode('utf-8')) + ' ' + str(item[1]) + '\n') |
SVilgelm
commented
Apr 1, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment