Python 201 Book Writing Update: Part 1 is Ready

I’ve been busily working on my second book, Python 201: Intermediate Python. In part one of the book, there are 10 chapters. I recently finished up the last chapter for that part of the book. While I have some tweaks I want to do to a couple of the chapters in this part of the book, I’m going to leave them alone for now so I can get part 2 done. Then I’ll be going back to part 1 to do some updates. This also allows the early adopters time to read the first chapters and send me messages about typos or bugs.

For those of you who didn’t get in on the Kickstarter for the book, the first 10 chapters are as follows:

  • Chapter 1 – The argparse module
  • Chapter 2 – The collections module
  • Chapter 3 – The contextlib module (Context Managers)
  • Chapter 4 – The functools module (Function overloading, caching, etc)
  • Chapter 5 – All about imports
  • Chapter 6 – The importlib module
  • Chapter 7 – Iterators and Generators
  • Chapter 8 – The itertools module
  • Chapter 9 – The re module (An Intro to Regex in Python)
  • Chapter 10 – The typing module (Type Hinting)

There are currently 71 pages in the book so far in my Gumroad edition and over 80 pages in the Leanpub version. Leanpub is generated differently which means they use different fonts and font sizes, which is why that version has more pages.  Regardless, the book is coming along well and is still on track for a September, 2016 release!

Python 201: An Intro to Iterators and Generators

You have probably been using iterators and generators since you started programming in Python but you may not have realized it. In this article, we will learn what an iterator and a generator are. We will also be learning how they are created so we can create our own should we need to.


An iterator is an object that will allow you to iterate over a container. The iterator in Python is implemented via two distinct methods: __iter__ and __next__. The __iter__ method is required for your container to provide iteration support. It will return the iterator object itself. But if you want to create an iterator object, then you will need to define __next__ as well, which will return the next item in the container.

Note: In Python 2, the naming convention was slightly different. You still needed __iter__, but __next__ was called next.

To make things extra clear, let’s go over a couple of definitions:

  • iterable – an object that has the __iter__ method defined
  • iterator – an object that has both __iter__ and __next__ defined where __iter__ will return the iterator object and __next__ will return the next element in the iteration.

Continue reading Python 201: An Intro to Iterators and Generators

PyDev of the Week: Mark Lutz

This week we have the honor of welcoming Mark Lutz as our PyDev of the Week. Mark is the author of the first Python book ever, Programming Python. He has also authored Learning Python and the Python Pocket Reference, all three of which were with O’Reilly publishing. Rather than rehash more of his background, let’s just jump into the interview so we can learn more about Mark Lutz!


Can you tell us a little about yourself (hobbies, education, etc):

I’m a software engineer, a Python book author and trainer, and one of the people who helped Python rise to the prominence it enjoys today.

I’ve been working in the software field for 3 decades, and earned BS and MS degrees in computer science from the University of Wisconsin. Back when I was being paid to do development, I worked on compilers for supercomputers and CAD systems, and large-scale applications at assorted start-ups.

Since quitting my “day job” two decades ago, I’ve been teaching Python classes in North America and Europe, and writing Python books that have sold over half a million units and span 11k published pages. To put that in perspective, back-of-the-envelope calculations suggest that the paper units of my books sold comprise about 650 tons (and counting).

If you’re interested in more details, check out my formal bio page at


Continue reading PyDev of the Week: Mark Lutz

PyDev of the Week: Nicole Harris

This week we welcome Nicole Harris (@nlhkabu) as our PyDev of the Week! Nicole is the lead designer of Warehouse, the replacement for the Python Packaging Index (PyPI). You can see a demo version of the site here. She is also working with O’Reilly publishing on a Django screencast, which you’ll hear more about below. Nicole also has a fun blog that is well worth checking out. Let’s take a few moments to get to know her better!

Can you tell us a little about yourself (hobbies, education, etc):

I’ve always been a creative person. I studied film and photography at university and got into web design (which eventually led me to Python) because I wanted to create an online portfolio of my animation works. I never launched that portfolio – but I did fall in love with the web.

In my spare time, I like to cook and sew. I’m also learning to speak French.

Continue reading PyDev of the Week: Nicole Harris

Python 201: An Intro to itertools

Python provides a great module for creating your own iterators. The module I am referring to is **itertools**. The tools provided by itertools are fast and memory efficient. You will be able to take these building blocks to create your own specialized iterators that can be used for efficient looping. In this chapter, we will be looking at examples of each building block so that by the end you will understand how to use them for your own code bases.

Let’s get started by looking at some infinite iterators!

Continue reading Python 201: An Intro to itertools

PyDev of the Month: Peter Damoc

This week we welcome Peter Damoc as our PyDev of the Week! I first came across some of Peter’s work in the wxPython source code. Let’s spend some time getting to know him better!

Can you tell us a little about yourself (hobbies, education, etc):

I’m 39 and I’m the oldest of five. I have three sisters and a brother that’s 20 years younger than me. I finished BioMedical Engineering with a degree in BioInstrumentation and most of my working experience has been in a plastic surgery clinic. I’ve used Python to implement a distributed patient management software for internal use and a series of softwares for breast implants selection, the most famous of them being BioDynamic Breast Analysis which got distributed internationally by Allergan. For the past 4 years I’ve been in an extended sabbatical exploring a career in coaching and training. My main hobby for the past 3 years has been Argentine Tango. Continue reading PyDev of the Month: Peter Damoc

Python 201 – What’s a deque?

According to the Python documentation, deques “are a generalization of stacks and queues”. They are pronounced “deck” which is short for “double-ended queue”. They are a replacement container for the Python list. Deques are thread-safe and support memory efficient appends and pops from either side of the deque. A list is optimized for fast fixed-length operations. You can get all the gory details in the Python documentation. A deque accepts a maxlen argument which sets the bounds for the deque. Otherwise the deque will grow to an arbitrary size. When a bounded deque is full, any new items added will cause the same number of items to be popped off the other end.

As a general rule, if you need fast appends or fast pops, use a deque. If you need fast random access, use a list. Let’s take a few moments to look at how you might create and use a deque.

>>> from collections import deque
>>> import string
>>> d = deque(string.ascii_lowercase)
>>> for letter in d:
...     print(letter)

Continue reading Python 201 – What’s a deque?

PyDev of the Week: John Cook

This week we welcome John Cook as our PyDev of the Week! John has a fun Python blog that I read from to time and he graciously accepted my offer of interviewing him this week. Let’s take a few moments to get to know him better.

Can you tell us a little about yourself (hobbies, education, etc):

I’m a consultant working in the overlap of math, data analysis, and software development. Most projects I do have two of these elements if not all three. I had a variety of jobs before starting my own company, and most of them involved some combination of math and software development.

  Continue reading PyDev of the Week: John Cook

Python 201 Kickstarter Update – The End is Nigh!

We are entering the last few days for the Kickstarter Campaign for my second book, Python 201. Since we’re almost to our stretch goal, I have added new chapters to the book. In addition to what was already covered, the book will also cover the following topics:

  • Python’s super()
  • descriptors (magic methods)
  • Scope (local, global and the new non_local)
  • typing
  • asyncio / await / async

That brings the total number of chapters up to 27! If you feel like contributing, you can do so here: