Skip to content

Instantly share code, notes, and snippets.

@joedougherty
Last active August 29, 2015 14:02
Show Gist options
  • Save joedougherty/fe84fcc4998849f7a04b to your computer and use it in GitHub Desktop.
Save joedougherty/fe84fcc4998849f7a04b to your computer and use it in GitHub Desktop.
from pprint import pprint
lens_to_test = range(2,26)
lengths = {}
def all_words():
all_words = []
words = '/usr/share/dict/words'
f = open(words,'r')
for w in f.readlines():
word = w.strip()
word = word.lower()
all_words.append(word)
return all_words
def palin_count_by_len(length, words):
count = 0
for w in words:
if len(w) == length and (w == w[::-1]):
count = count + 1
lengths[length] = count
word_list = all_words()
for l in lens_to_test:
palin_count_by_len(l, word_list)
pprint(lengths)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment