Table of Contents for
Tiny Python Projects

Cover image for Tiny Python Projects Tiny Python Projects by Ken Youens-Clark Published by Manning Publications, 2020
  1. Tiny Python Projects (01:09 mins)
  2. Copyright (02:18 mins)
  3. brief contents (01:09 mins)
  4. contents (06:54 mins)
  5. front matter (09:12 mins)
  6. 0 Getting started: Introduction and installation guide (23:00 mins)
  7. 1 How to write and test a Python program (35:39 mins)
  8. 2 The crow’s nest: Working with strings (36:48 mins)
  9. 3 Going on a picnic: Working with lists (34:30 mins)
  10. 4 Jump the Five: Working with dictionaries (26:27 mins)
  11. 5 Howler: Working with files and STDOUT (26:27 mins)
  12. 6 Words count: Reading files and STDIN, iterating lists, formatting strings (18:24 mins)
  13. 7 Gashlycrumb: Looking items up in a dictionary (16:06 mins)
  14. 8 Apples and Bananas: Find and replace (35:39 mins)
  15. 9 Dial-a-Curse: Generating random insults from lists of words (26:27 mins)
  16. 10 Telephone: Randomly mutating strings (21:51 mins)
  17. 11 Bottles of Beer Song: Writing and testing functions (28:45 mins)
  18. 12 Ransom: Randomly capitalizing text (20:42 mins)
  19. 13 Twelve Days of Christmas: Algorithm design (27:36 mins)
  20. 14 Rhymer: Using regular expressions to create rhyming words (40:15 mins)
  21. 15 The Kentucky Friar: More regular expressions (34:30 mins)
  22. 16 The scrambler: Randomly reordering the middles of words (20:42 mins)
  23. 17 Mad Libs:Using regular expressions (23:00 mins)
  24. 18 Gematria: Numeric encoding of text using ASCII values (24:09 mins)
  25. 19 Workout of the Day: Parsing CSV files, creating text table output (35:39 mins)
  26. 20 Password strength: Generating a secure and memorable password (33:21 mins)
  27. 21 Tic-Tac-Toe: Exploring state (27:36 mins)
  28. 22 Tic-Tac-Toe redux: An interactive version with type hints (25:18 mins)
  29. Epilogue (03:27 mins)
  30. Appendix. Using argparse (35:39 mins)
  31. index (18:24 mins)

Epilogue

Well, that’s the whole book. We came a long way, from writing the crow’s nest program in chapter 2 to chapter 22’s interactive Tic-Tac-Toe game, incorporating a custom class based on named tuples and using type hints. I hope you can see now how much you can do with Python’s strings, lists, tuples, dictionaries, sets, and functions. I especially hope I’ve convinced you that, above all, you should always write programs that are

  • Flexible, by taking command-line arguments

  • Documented, by using something like argparse to parse your arguments and produce usage statements

  • Tested, by writing both unit tests for your functions and integration tests for your program as a whole

The people using your programs will really appreciate knowing how to use your program and how to make it behave differently. They’ll also appreciate that you took the time to verify that your program is correct. Let’s be honest, though. The person most likely to be using and modifying your programs will be you, several months from now. I’ve heard it said that “documentation is a love letter to your future self.” All this work you put into making your programs good will be very appreciated by you when you come back to your code.

Now that you’ve worked through all the exercises and seen how to use the tests I’ve written, I challenge you to go back to the beginning and read the test.py programs. If you intend to adopt test-driven development, you may find that you can steal many ideas and techniques from those programs.

Further, each chapter included suggestions for how to extend the ideas and exercises presented. Go back and think about how you can use ideas you learned later in the book to improve or extend earlier programs. Here are some ideas:

  • Chapter 2 (The crow’s nest)--Add an option to randomly select a greeting other than “Hello” from a list like “Hello,” “Hola,” “Salut,” and “Ciao.”

  • Chapter 3 (Going on a picnic)--Allow the program to take one or more options and incorporate those into the output with the correct articles for each item joined on the Oxford comma.

  • Chapter 7 (Gashlycrumb)--Download The Devil’s Dictionary by Ambrose Bierce from Project Gutenberg. Write a program that will look up a word’s definition if it appears in the text.

  • Chapter 16 (The scrambler)--Use the scrambled text as the basis for encrypting messages. Force the scrambled words to uppercase, remove all the punctuation and spaces, and then format the text into “words” of five characters followed by a space, with no more than five per line. Pad the end so that the text completely fills the last line. Can you make sense of the output?

  • new.py--I first wrote a program to create a new program when I was a greenhorn Perl hacker. My new-pl program would add a random quote from the poetry of William Blake (yes, really--I also went through phases with the Brontes and Dickinson). Alter your version of new.py to add a random quote or joke or to customize it in some way for your programs.

I hope you’ve had as much fun writing the programs as I’ve had creating and teaching them. I want you to feel you now have dozens of programs and tests with ideas and functions you can steal to create even more programs.

All the best to you in your coding adventures!


    Reset