Most "Python one-liners" lists are party tricks you never use again. These five made it into my real scripts and stayed there.
1. Read a file into a list of clean lines
lines = [l.strip() for l in open("data.txt") if l.strip()] One pass, skips blank lines, no ceremony. I use this for every quick data job.
2. Count things without boilerplate
from collections import Counter counts = Counter(words) counts.most_common(3) answers "what shows up most" in a single call. Stop writing histogram loops by hand.
3. Swap two variables
a, b = b, a No temp variable. Tuple unpacking is one of those small things that makes Python feel like Python.
4. Flatten a list of lists
flat = [x for row in grid for x in row] Read it as English: "x for each row in grid, for each x in row." Once it clicks, you stop reaching for nested loops.
5. Merge two dictionaries (3.9+)
config = defaults | overrides The | operator merges without mutating either dict. Clean defaults-plus-overrides in one line.
None of these are clever for the sake of clever. They survive code review, and that's the bar that matters. What one-liner do you actually use? Drop it in the comments. x