Created
March 3, 2010 09:28
-
-
Save pervognsen/320475 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def normalize(word): | |
return word.lower() | |
def coordinates(word): | |
word = normalize(word) | |
coords = [0] * 26 | |
for char in word: | |
coords[ord(char) - ord('a')] += 1 | |
return tuple(coords) | |
words = [] | |
histogram = {} | |
for word in open("/usr/share/dict/words"): | |
word = word.strip() | |
words.append(word) | |
coords = coordinates(word) | |
histogram[coords] = 1 + histogram.get(coords, 0) | |
print len(words) | |
print len(histogram) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment