python

Python List Comprehensions

Carl Sampson
Python List Comprehensions is a pretty interesting feature that I haven’t seen in other languages (at least that I’ve played with). The basic idea is that they create lists from other iterables. They consists of brackets containing the expression which is executed against each item in the iterable object. One or more conditionals dictate if the item is added to the new list. The basic format is – list = [expression for_loop_one_or_more conditions]