major updates to the solutions
[wordplay-cdsw-solutions] / solution_2.py
1 import scrabble
2
3 # What is the longest word that starts with a q?
4
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     if word[0] == 'q':
12         if len(word) > len(longest_so_far): # Question: What if I use >= rather than > here?
13             longest_so_far = word
14
15 print(longest_so_far)

Benjamin Mako Hill || Want to submit a patch?