Initial commit: basic exercises
[wordplay-cdsw-solutions] / solution_2.py
1 import scrabble
2
3
4 # What is the longest word that starts with a q?
5 # This is the most common student solution, which prints the *first* occurence of
6 # the longest word. See solution_2_advanced.py for more info.
7
8 longest_so_far = '' # Store the longest word we've seen up to this point.
9
10 for word in scrabble.wordlist:
11
12     if word[0] == 'q':
13         if len(word) > len(longest_so_far):  # What if I use >= rather than > here?
14             longest_so_far = word
15             #print word  # Use this to see the progression.
16
17
18 print longest_so_far
19             
20
21

Benjamin Mako Hill || Want to submit a patch?