reworked these examples a bit based on feedback in class
[wordplay-cdsw-solutions] / solution_5_advanced.py
1 import scrabble
2
3
4 # This is a solution to 5 that reuses the code in 1.  Whenever we can,
5 # it's good to reuse code that we already have.  In a future session,
6 # we'll talk about defining functions, which is the way programmers
7 # re-use code.
8
9 matching_words = []
10
11 for word in scrabble.wordlist:
12     if word[0] == 'a' and len(word) >= 9:
13         matching_words.append(word)
14
15
16 # Note that I use enumerate. You can look up the enumerate function
17 # online to see what it does. We're also using a new operating "%"
18 # which is the modulo operator and which is more flexible than the
19 # "bool" based version we used before.
20
21 for i, word in enumerate(matching_words):
22     if i % 2 == 0:
23         print(word)

Benjamin Mako Hill || Want to submit a patch?