reworked these examples a bit based on feedback in class
[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 somewhat ill-specified. What if there isn't a
6 # single longest word? What if there is a tie?
7
8 # We designed this problem with that ambiguity in mind, because
9 # sometimes the thing we want to measure may not exist, or may not
10 # exist in the way we anticipate.
11
12 # This solution keeps EVERY word of the longest length.
13
14 longest_so_far = [] 
15 length_of_longest_word = 0
16
17 for word in scrabble.wordlist:
18     if word[0] == 'q':
19         if len(word) > length_of_longest_word:
20             length_of_longest_word = len(word)
21             longest_so_far = [word]
22         elif len(word) == length_of_longest_word:
23             longest_so_far.append(word)
24             #print longest_so_far  # Use this to see the progression.
25
26 print(longest_so_far)

Benjamin Mako Hill || Want to submit a patch?