Listcomprehensions in python

List comprehensions provide a concise way to create lists. They can include conditions and nested loops. Dict and set comprehensions work similarly. They're more Pythonic and often faster than equivalent for loops.

Example

# List comprehension
squares = [x**2 for x in range(10)]

# With condition
evens = [x for x in range(20) if x % 2 == 0]

# Dict comprehension
word_lengths = {w: len(w) for w in ["hello", "world"]}

Comprehensions express data transformations in a single readable line.