A Python Puzzle

A few months ago, while refreshing my Python knowledge, I came up with this little puzzle; Given a collections.defaultdict, how can you have it use a counter for the defaults, i.e. 1 for the first lookup that’s not found, 2 for the second, etc? At the time I also wanted to learn about Jupyter notebooks, so I made a notebook with the puzzle and my solutions (I found five) and put it up on GitHub. Some time after I also posted the puzzle to Reddit to see if anyone would come up with additional solutions… nobody did, but they did find a few ways to turn some of the five solutions into one-liners which I added to the notebook.

Finding solutions to the puzzle is not hard, although finding all five will take some thinking. Simple though it is, this puzzle is a useful exploration of the ways you can encapsulate non-local state in Python.

The notebook with the solutions is here.

Site Launch

So this is my new website. It’s a static site built using Jekyll, a static site builder written in Ruby, and based on Hyde, a Jekyll theme by @mdo, the author of bootstrap.

There are a lot of static site generators to chose from, but of the ones that are widely used and being actively developed, Jekyll seems to be the most popular as well as one of the oldest, and thus has a huge ecosystem, including lots of ready-to-use themes. Although my needs here are very modest, I plan to use the same site generator for some other little projects and to build some modern website design skills, so it will be good to have plenty of examples from professional designers to study and play around with.