[x^2 for x in lst]

Python Workout

Author: Reuven M. Lerner

Review created: 2022-09-20

Pythonic Workout by Reuven Lerner is one of the most useful, if not the most useful programming related books that I've ever read. It suits me perfectly. The book contains 51 exercises with full solutions and explanations for the solutions. It also contain links to video snippets where the author goes through the solutions and adds more context to them. To me who likes to learn programming by writing code (is there another way?), this is perfect. I get to try my hands at writing a Python program to solve a problem and then get to compare my solution with the solution of a master Python programmer. Perfect.

Note that the exercises are quite Python specific. There is most often not an easy translation of the problem from Python to another programming language. You can for example be asked to write a generator function that returns all line of all files in a directory one by one.

The exercises does not demand very long solutions, as is hinted by the subtitle of the book - "50 ten-minute exercises". I cannot say that I solved every exercise in ten minutes, for most of them I had to work a bit longer, but I usually managed to work through them in a reasonable amount of time. The resulting Python programs are often quite short, sometimes only five to ten rows of code. Some of the solutions are of course longer, but most of them are fairly short.

For each of the exercises in the book, there thee more exercises in a section called "Beyond the exercise". These are often variants of the original exercise with small tweaks.

The exercises in the book are divided into ten chapters, each containing exercises related to a specific topic. The names of the chapters are:

  • Numeric types
  • Strings
  • Lists and tuples
  • Dictionaries and sets
  • Files
  • Functions
  • Functional programming with comprehensions
  • Modules and packages
  • Objects
  • Iterators and generators

Each chapter starts off with a small tutorial of the topic of the chapter. It also includes a table listing all, or at least most of, the Python constructs needed to solve the exercises in the chapter. After the tutorial has ended, the real meat of the chapter, the exercises starts. In the end of each chapter there is a brief discussion about what the chapter has covered.

As there are 51 * (1 + 3) == 204 exercises in total, it will take some time to work through all of them. I bought the book when it was in MEAP and started to work myself through the exercises little by little, perhaps doing one exercise a month or so. In June 2022 I decided that the progress was too slow, so I set up a goal of doing 2 exercises a day until the book was finished. I managed to stick to this plan, with exceptions for days I were travelling but I compensated for those by doing more exercises the following days. This way I was able to finish the book three months after I started working according to my plan. It was a bit of an effort, but was totally worth it :)

You should not read this book if you has never programmed at all. If you know another programming language or have a bit of Python knowledge under your belt, this book is absolutely for you. The exercises are not very complex and the author does a great job of explaining the Python concepts needed to solve them. If you are a seasoned Python programmer you probably would benefit from reading the book as well as the topics it covers are quite broad, so chances are that you might pick up a thing or two that you did not already know.

Summary: Pythonic Programming is a really, really good book. I learned a lot about programming in Python from it. Is is written in an easy manner with a good portion of humour added in between the Python facts. For those who likes to listen and watch to learn, the videos are great as well. Expect to put in a lot of time if you want to solve all exercises. However, as the format of the book is such that each exercise stands on its own, you can solve one exercise and wait for a while until you solve the next without loosing any context. I recommend this book to all Python (and non-Python) prgrammers! I just wish there was more books like this for other programming languages.