← All posts
postMay 18, 2026
Python list comprehensions — short, fast, readable
#python#list-comprehension#intermediate
python
rows = [{"name": "alice", "age": 30},
{"name": "bob", "age": 17},
{"name": "carol", "age": 25}]
# extract names of adults
adults = [r["name"] for r in rows if r["age"] >= 18]
print(adults) # ['alice', 'carol']A list comprehension builds a new list by transforming each item from another iterable. It is shorter, faster, and more idiomatic than a regular for-loop with append().
In data engineering you transform lists constantly — extract a single field from each record, convert types, filter rows. List comprehensions make this code half the length and easier to scan. Master them and your scripts immediately look more professional.