List comprehensions are a concise and elegant way to create new lists in Python. They provide a compact syntax for generating lists based on existing iterables or performing transformations on elements of an iterable.
Example:
numbers = [1, 3, 5, 7, 9, 10, 12]
squared = [num**2 for num in numbers if num > 5]
In this example, the list comprehension iterates over each number in the numbers list. It applies the expression num**2 to each number and adds the result to the new list squared only if the number is greater than 5. The resulting squared list will contain the squares of numbers greater than 5, which are 49, 81, 100, and 144.