Tutorial: List Comprehensions in Python
Channel: lattyware
Date: 2012-11-03

List comprehensions are a really powerful tool that every Python programmer should know, they often reduce many lines of awkward, hard to read code down to a single line. Most Python code you will find will be full of them for good reason.

This is an updated version of my video where I explain list comprehensions (alongside set/dictionary comprehensions and generator expressions). This new version has better audio, has cut some of the intro stuff and has a few extra nuggets of information.

Please note that set and dictionary comprehensions are a feature of Python 2.7+, so if you are using an older version, you will not be able to use them (as an alternative, use a generator expression to the set() builtin or one producing (key, value) tuples in the dict() builtin as appropriate).

I am using PyCharm (http://www.jetbrains.com/pycharm/) as my editor, and I highly recommend it. It's not free, and while you definitely don't *need* an IDE to work in Python, for more complex tasks it's very nice to have a good one. The font I'm using is Source Code Pro, which is freely available at http://sourceforge.net/projects/sourcecodepro.adobe/.