Skip to content

Instantly share code, notes, and snippets.

@michaeluzzi
Created February 27, 2013 18:42
Show Gist options
  • Save michaeluzzi/5050428 to your computer and use it in GitHub Desktop.
Save michaeluzzi/5050428 to your computer and use it in GitHub Desktop.
Outputs the words of Kim and Kanye's tweets, sorted.
import sys
all_concordance = dict()
for line in open('kim-tweets.txt'):
line = line.strip()
line = line.replace(".", "")
line = line.replace(",", "")
line_words = line.split(" ")
for word in line_words:
if word in all_concordance:
all_concordance[word] += 1
else:
all_concordance[word] = 1
for line in open('kanye-tweets.txt'):
line = line.strip()
line = line.replace(".", "")
line = line.replace(",", "")
line_words = line.split(" ")
for word in line_words:
if word in all_concordance:
all_concordance[word] += 1
else:
all_concordance[word] = 1
output = ""
sorted_concordance = sorted(all_concordance)
for word in sorted_concordance:
output += word
output += " "
print output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment