[Python] List Comprehensions Explained with Color Coding

Trent Robbins robbintt at gmail.com
Wed Dec 2 23:43:11 UTC 2015

This made hacker news today:


List comprehensions are a way of doing a for loop that returns a list,
everything that they can do can be done WITHOUT list comprehensions, but as
you become more fluent with them they can provide very good readability
when used in the right place.

As many of you know I don't think they should always be used, but I have
started using them for some simple munging (mostly filtering other data
structures, like a dict that you programatically need only a small part of)
because they provide an educated reader a quick summary of the events

Some negatives: list comprehensions don't always refactor well, generally
you'd end up totally rewriting that section.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.noisebridge.net/pipermail/python/attachments/20151202/286d3d55/attachment-0002.html>

More information about the Python mailing list