List comprehensions provide a concise way to create lists from existing lists. Each list comprehension consists of an expression followed by a for clause, then zero or more for or if clauses. The result will be a list resulting from evaluating the expression in the context of the for and if clauses which follow it.
The following are common ways to describe lists (or sets, or tuples, or vectors) in mathematics.
Lists can contain any type of elements, including strings, nested lists and functions. We can even mix different types within a list.
The following works on a list of strings and produces a list of lists.
The following is also an example of nested list comprehension: