You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write a Python program called `helper.py` that finds all words matching a given `-p|--pattern` such as one might use to complete a crossword puzzle to find words matching from a given `-w|--wordlist` (default `/usr/share/dict/words`). E.g., all 5-letter words with a "t" as the second character and ending in "ed". I could do this on the command line like so:
4942
5028
@@ -5188,7 +5274,7 @@ If both conditions are `True` (same length, all characters the same), then I `ap
5188
5274
All that is left is to check if any words matched. If so, we print them out, numbered and nicely aligned; otherwise, we let the user know that no matches were found. I hope you tried solving this problem with and without regular expressions as there is much to learn by each method.
5189
5275
\newpage
5190
5276
5191
-
# Chapter 20: Kentucky Friar
5277
+
# Chapter 21: Kentucky Friar
5192
5278
5193
5279
Write a Python program called `friar.py` that reads some input text from a single positional argument on the command line (which could be a file to read) and transforms the text by dropping the "g" from words two-syllable words ending in "-ing" and also changes "you" to "y'all". Be mindful to keep the case the same on the first letter, e.g, "You" should become "Y'all," "Hunting" should become "Huntin'".
5194
5280
@@ -5368,7 +5454,7 @@ Finally we need to apply our `fry` function to all the pieces we got from splitt
5368
5454
````
5369
5455
\newpage
5370
5456
5371
-
# Chapter 21: Mad Libs
5457
+
# Chapter 22: Mad Libs
5372
5458
5373
5459

5374
5460
@@ -5680,7 +5766,7 @@ The `count=1` is necessary to prevent `re.sub` from replacing *every* instance o
5680
5766
5681
5767
\newpage
5682
5768
5683
-
# Chapter 22: License Plates
5769
+
# Chapter 23: License Plates
5684
5770
5685
5771
Write a Python program called `license.py` that will create a regular expression for a license plate that accounts for characters and numbers which might be confused according to the following list:
5686
5772
@@ -5813,7 +5899,7 @@ In creating all the possible plates from your regular expression, you are making
5813
5899
5814
5900
\newpage
5815
5901
5816
-
# Chapter 23: Gibberish Generator
5902
+
# Chapter 24: Gibberish Generator
5817
5903
5818
5904
Write a Python program called `gibberish.py` that uses the Markov chain algorithm to generate new words from the words in a set of training files. The program should take one or more positional arguments which are files that you read, word-by-word, and note the options of letters after a given `-k|--kmer_size` (default `2`) grouping of letters. E.g., in the word "alabama" with `k=1`, the frequency table will look like:
5819
5905
@@ -6284,7 +6370,7 @@ Now you can talk the "Markov Chain" problem that moves to the level of words and
6284
6370
6285
6371
\newpage
6286
6372
6287
-
# Chapter 24: Piggy (Pig Latin)
6373
+
# Chapter 25: Piggy (Pig Latin)
6288
6374
6289
6375
Write a Python program named `piggy.py` that takes one or more file names as positional arguments and converts all the words in them into "Pig Latin" (see rules below). Write the output to a directory given with the flags `-o|--outdir` (default `out-yay`) using the same basename as the input file, e.g., `input/foo.txt` would be written to `out-yay/foo.txt`.
6290
6376
@@ -6694,7 +6780,7 @@ That is the crux of the program. All that is left is to report to the user how m
6694
6780
6695
6781
\newpage
6696
6782
6697
-
# Chapter 25: Soundex Rhymer
6783
+
# Chapter 26: Soundex Rhymer
6698
6784
6699
6785
Write a Python program called `rhymer.py` that uses the Soundex algorithm/module to find words that rhyme with a given input word. When comparing words, you sometimes want to discount any leading consonants, e.g., the words "listen" and "glisten" rhyme but only if you compare the "isten" part, so the program should have an optional flag `-s|--stem` to indicate that the given word and the words you compare should both be trimmed to the "stem". The program should take an optional `-w|--wordlist` argument (default `/usr/share/dict/words`) for the comparisons and should respond, as always, to `-h|--help` for usage.
6700
6786
@@ -7013,7 +7099,7 @@ Once I have the `stemmer` function, I can apply it to the given `word` and every
7013
7099
7014
7100
\newpage
7015
7101
7016
-
# Chapter 26: Anagram
7102
+
# Chapter 27: Anagram
7017
7103
7018
7104
Write a program called `presto.py` that will find anagrams of a given positional argument. The program should take an optional `-w|--wordlist` (default `/usr/share/dict/words`) and produce output that includes combinations of `-n|num_combos` words (default `1`) that are anagrams of the given input.
7019
7105
@@ -7463,7 +7549,7 @@ In the end, I look to see how many `anagrams` I found using `len(anagrams)`. If
7463
7549
7464
7550
\newpage
7465
7551
7466
-
# Chapter 27: Hangman
7552
+
# Chapter 28: Hangman
7467
7553
7468
7554
Write a Python program called `hangman.py` that will play a game of Hangman which is a bit like "Wheel of Fortune" where you present the user with a number of elements indicating the length of a word. For our game, use the underscore `_` to indicate a letter that has not been guessed. The program should take `-n|--minlen` minimum length (default `5`) and `-l|--maxlen` maximum length options (default `10`) to indicate the minimum and maximum lengths of the randomly chosen word taken from the `-w|--wordlist` option (default `/usr/share/dict/words`). It also needs to take `-s|--seed` to for the random seed and the `-m|--misses` number of misses to allow the player.
7469
7555
@@ -8033,7 +8119,7 @@ Here are some changes you could make to your program:
8033
8119
* Add a `quiet` flag to keep `play` from executing any `print` statements
8034
8120
\newpage
8035
8121
8036
-
# Chapter 28: First Bank of Change
8122
+
# Chapter 29: First Bank of Change
8037
8123
8038
8124
Write a Python program called `fboc.py` that will figure out all the different combinations of pennies, nickels, dimes, and quarters in a given `value` provided as a single positional argument. The value must be greater than 0 and less than or equal to 100. It should provide a usage if given no arguments or the `-h|--help` flag:
8039
8125
@@ -8275,7 +8361,7 @@ The `plural` version of each name is made by adding `s` except for `penny`, so l
8275
8361
Finally lines 39-43 are left to formatting the report to the user, being sure to provide feedback that includes the original `value` ("If you give me ...") and an enumerated list of all the possible ways we could make change. The test suite does not bother to check the order in which you return the combinations, only that the correct number are present and they are in the correct format.
8276
8362
\newpage
8277
8363
8278
-
# Chapter 29: Runny Babbit
8364
+
# Chapter 30: Runny Babbit
8279
8365
8280
8366
Are you familiar with Spoonerisms where the initial consonant sounds of two words are switched? According to Wikipedia, they get their name from William Archibald Spooner who did this often. The author Shel Silverstein wrote a wonderful book called _Runny Babbit_ ("bunny rabbit") based on this. So, let's write a Python program called `runny_babbit.py` that will read some text or an input file given as a single positional argument and finds neighboring words with initial consonant sounds to swap. As we'll need to look at pairs of words and in such as way that it will make it difficult to remember the original formatting of the text, let's also take a `-w|--width` (default `70`) to format the output text to a maximum width.
8281
8367
@@ -8559,7 +8645,7 @@ The runny babbit is cute.
8559
8645
````
8560
8646
\newpage
8561
8647
8562
-
# Chapter 30: Markov Chain
8648
+
# Chapter 31: Markov Chain
8563
8649
8564
8650
Write a Python program called `markov.py` that takes one or more text files as positional arguments for training. Use the `-n|--num_words` argument (default `2`) to find clusters of words and the words that follow them, e.g., in "The Bustle" by Emily Dickinson:
8565
8651
@@ -8820,7 +8906,7 @@ But there will be spaces in between each word, so I account for them by adding o
8820
8906
At this point, the `words` list needs to be turned into text. It would be ugly to just `print` out one long string, so I use the `textwrap.wrap` to break up the long string into lines that are no longer than the given `text_width`. That function returns a list of lines that need to be joined on newlines to print.
8821
8907
\newpage
8822
8908
8823
-
# Chapter 31: Hamming Chain
8909
+
# Chapter 32: Hamming Chain
8824
8910
8825
8911
Write a Python program called `chain.py` that takes a `-s|--start` word and searches a `-w|--wordlist` argument (default `/usr/local/share/dict`) for words no more than `-d|--max_distance` Hamming distance for some number of `-i|--iteration` (default `20`). Be sure to accept a `-S|--seed` for `random.seed`.
8826
8912
@@ -9023,7 +9109,7 @@ Failed to find more words!
9023
9109
9024
9110
\newpage
9025
9111
9026
-
# Chapter 32: Morse Encoder/Decoder
9112
+
# Chapter 33: Morse Encoder/Decoder
9027
9113
9028
9114
Write a Python program called `morse.py` that will encrypt/decrypt text to/from Morse code. The program should expect a single positional argument which is either the name of a file to read for the input or the character `-` to indicate reading from STDIN. The program should also take a `-c|--coding` option to indicate use of the `itu` or standard `morse` tables, `-o|--outfile` for writing the output (default STDOUT), and a `-d|--decode` flag to indicate that the action is to decode the input (the default is to encode it).
9029
9115
@@ -9241,7 +9327,7 @@ THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
9241
9327
9242
9328
\newpage
9243
9329
9244
-
# Chapter 33: ROT13 (Rotate 13)
9330
+
# Chapter 34: ROT13 (Rotate 13)
9245
9331
9246
9332
Write a Python program called `rot13.py` that will encrypt/decrypt input text by shifting the text by a given `-s|--shift` argument or will move each character halfway through the alphabet, e.g., "a" becomes "n," "b" becomes "o," etc. The text to rotate should be provided as a single positional argument to your program and can either be a text file, text on the command line, or `-` to indicate STDIN so that you can round-trip data through your program to ensure you are encrypting and decrypting properly.
9247
9333
@@ -9406,7 +9492,7 @@ The quick brown fox jumps over the lazy dog.
9406
9492
9407
9493
\newpage
9408
9494
9409
-
# Chapter 34: Word Search
9495
+
# Chapter 35: Word Search
9410
9496
9411
9497
Write a Python program called `search.py` that takes a file name as the single positional argument and finds the words hidden in the puzzle grid.
0 commit comments