Whitespace corrections, a couple bug fixes, replacing a format string with constructi...
[wordplay-cdsw-solutions] / solution_2_advanced.py
1 import scrabble
2
3 # What is the longest word that starts with a q?
4
5 # This problem was ill-specified. What if there isn't a single longest word? What if
6 # there is a tie? 
7 # We designed this problem with that ambiguity in mind, because sometimes the thing
8 # we want to measure may not exist, or may not exist in the way we anticipate.
9
10 # This solution keeps EVERY word of the longest length.
11
12 longest_so_far = [] 
13 length_of_longest_word = 0
14
15 for word in scrabble.wordlist:
16
17     if word[0] == 'q':
18         if len(word) > length_of_longest_word:
19             length_of_longest_word = len(word)
20             longest_so_far = [word]
21         elif len(word) == length_of_longest_word:
22             longest_so_far.append(word)
23             #print longest_so_far  # Use this to see the progression.
24
25 print longest_so_far

Benjamin Mako Hill || Want to submit a patch?