Tuesday, December 09, 2008

Downtown Ice (San Jose)

Here's a cute puzzle: find the longest words you can type with just your left hand.

Solution:

#!/usr/bin/python2.4
import sys
import os

DICTIONARY = '/usr/share/dict/american-english'
left_hand_letters = set('qwertasdfgzxcvb')
list_of_words = os.popen("cat %s | tr [A-Z] [a-z]" % DICTIONARY)

longest = 0
for word in list_of_words:
  if (not [i for i in word.strip() if i not in left_hand_letters]
      and len(word) >= longest):
    longest = len(word)
    print word,

0 Comments:

Post a Comment

<< Home