list.reverse()
Reverse the list in place — mutates, returns None. The mirror of the reversed() builtin, which is pure.
Common call
items.reverse()
Returns
None — the list itself is flipped
Replaces
building a reversed copy when you own the list
Watch out
the classic bug: `xs = xs.reverse()` sets xs to None
list.reverse()
→ None
Demo
Live evaluation
Try:
Inputs
itemslistcomma-separated items
Output
['a', 'b', 'c', 'd'].reverse()
None
The demo shows the LIST STATE after reversing. Python actually returns None; the meaningful effect is mutation. reverse() is destructive and O(n) in place — no copy. Compare with reversed(xs) which returns a lazy iterator without touching the source, and xs[::-1] which returns a materialized reversed copy.
Common patterns
Reverse a working buffer
When you own the list and no other reference needs the original order.
buffer.reverse()
Bottom-up processing after collection
Collect forward, process backward — one flip beats indexing tricks.
events.reverse() for event in events: replay(event)
Two-step round trip
Applying reverse twice restores the original order — useful in tests.
xs.reverse() # ... do stuff ... xs.reverse() # original order again
Examples
1. Basic
xs = [1, 2, 3]
xs.reverse()
xs
Returns
[3, 2, 1]2. Single item
xs = ["a"]
xs.reverse()
xs
Returns
["a"]3. Empty
xs = []
xs.reverse()
xs
Returns
[]4. Returns None (surprise)
[1, 2, 3].reverse()
Returns
None5. Two calls restore
xs = [1, 2, 3]
xs.reverse()
xs.reverse()
xs
Returns
[1, 2, 3]Pitfalls
1. The `xs = xs.reverse()` bug
reverse() returns None. Assigning its result back sets your variable to None — the original list is now unreachable through xs. Same class of bug as sort, extend, and insert.
Now xs is None
xs = [1, 2, 3] xs = xs.reverse() print(xs)
None
Two options
xs.reverse() # mutate, keep name # or xs = xs[::-1] # new list, replace name
[3, 2, 1]
2. Only works on lists
reverse is a list METHOD. Tuples, strings, ranges, sets, dicts, generators — none of them have it. Reach for reversed() when the source is not a mutable list.
AttributeError
(1, 2, 3).reverse()
AttributeError: 'tuple' object has no attribute 'reverse'
reversed() works
list(reversed((1, 2, 3)))
[3, 2, 1]
3. Confused with reversed() and [::-1]
Three different tools with three different shapes: reverse() mutates and returns None; reversed(xs) returns a lazy iterator and leaves xs alone; xs[::-1] returns a materialized reversed copy. Pick the one that matches the intent.
Mutating when you meant a copy
ys = xs.reverse() # now ys is None and xs is flipped
both variables surprising
Pick your intent
ys = xs[::-1] # copy, xs untouched ys = list(reversed(xs)) # copy via iterator xs.reverse() # mutate xs, no new list
clear intent
When to use
Use it
- You own the list and no one else needs the original order
- Working buffers where allocating a copy would hurt
- Two-pass algorithms that flip and iterate
Reach for something else
- You need to keep the original → xs[::-1] copy
- One-liners in a chain (reverse returns None, breaks the chain)
- Concurrent readers of the same list
- Non-list sources → reversed()
Notes
Complexity
O(n)
Return
None; the list is mutated in place
CPython impl
Objects/listobject.c :: list_reverse_impl — in-place three-swap loop
Memory
In-place; no new list allocated
Thread-safe
Not safe under concurrent reads or writes of the same list
FAQ
Python returns None from mutating list methods on purpose — a signal that the operation modified the receiver. It also discourages the `xs = xs.reverse()` bug (mildly — it happens anyway).
History
1.0
list.reverse has been part of the list type since Python 1.0.
2.4
reversed() builtin added — the pure counterpart.