Python Workshops for Beginners/Saturday September 27th homework: Difference between revisions

imported>Ynasser
imported>Ynasser
Line 56:
 
== Wordplay Exercises ==
Here's a [https://openhatch.org/wiki/Wordplay_handout link] to the Wordplay handout if you need a review. Exercise 3 requires knowledge of regular expressions. If you need solutions to the wordplay exercises to see example of regular expressions in action, [https://github.com/jesstess/Wordplay they can be found here].
 
Make sure to navigate to the wordplay-exercises directory and put your python files there for this problem.
 
'''Exercise 3'''
 
This exercise requires knowledge of regular expressions. If you need solutions to the wordplay exercises to see example of regular expressions in action, [https://github.com/jesstess/Wordplay they can be found here].
 
Write a program to find all words in the scrabble dictionary which contain a q which isn't followed by a u.
 
To do this problem, you'll need something which isn't covered in the Wordplay handout. If you want to look for a string which contains "in" but isn't immediately followed by a "g", you'd douse this as your pattern:
 
<pre>
>>> pattern = re.compile("in[^g]")
>>>
</pre>
 
To get started, recall that you need to import the regular expressions and scrabble modules:
<pre>
>>> import re
>>> import scrabble
</pre>
 
The scrabble wordlist can be accessed by:
<pre> words = scrabble.wordlist
</pre>
'''Exercise 4'''
 
Find
Anonymous user