Python Workshops for Beginners/Saturday September 27th homework: Difference between revisions
Content added Content deleted
imported>Ynasser |
imported>Ynasser |
||
Line 56: | Line 56: | ||
== Wordplay Exercises == |
== Wordplay Exercises == |
||
Here's a [https://openhatch.org/wiki/Wordplay_handout link] to the Wordplay handout if you need a review. |
Here's a [https://openhatch.org/wiki/Wordplay_handout link] to the Wordplay handout if you need a review. |
||
Make sure to navigate to the wordplay-exercises directory and put your python files there for this problem. |
|||
'''Exercise 3''' |
'''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. |
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 |
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 use this as your pattern: |
||
<pre> |
<pre> |
||
>>> pattern = re.compile("in[^g]") |
|||
>>> |
|||
</pre> |
</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''' |
'''Exercise 4''' |
||
Find |