Reversing
Reversing is an operation that produces a sequence's elements in the opposite order, either by modifying the source or returning a reversed sequence.
Fabulous Adventures in Data Structures and Algorithms
Reverse is a method that constructs a new immutable linked list containing the input list's items in reverse order.
- How it is used
- Builds a reversed immutable list and transfers queued items between stacks when an immutable queue needs a new dequeue stack.
- How deep it goes
- Works through an iterative C# implementation, unchanged-input behavior, and O(n) time and extra-memory costs.
- Examples
- Tests reversal of a five-item integer list and uses stack reversal in an enqueue-and-dequeue sequence.
- What you can do after
- Build it from scratch with an empty accumulator and repeated Push calls, then apply the same pattern to an immutable queue.
Read how Fabulous Adventures in Data Structures and Algorithms explains reversing →
Python How-To
The reverse method is a Python list method that reverses a list in place and returns None.
- How it is used
- Use reversing to mutate a list into reverse order before subsequent readable, left-to-right operations.
- How deep it goes
- Defines in-place mutation and the None return, then contrasts reverse() with reversed() and negative-step slicing.
- Examples
- Demonstrates reversing before slicing and contrasts it with iterating through reversed(tasks).
- What you can do after
- Apply it to reverse an existing list in place and avoid treating its None return as reversed data.
The Quick Python Book, Fourth Edition
The reverse method is a Python list operation that reverses the order of elements in the list in place.
- How it is used
- Applies an in-place operation when a list’s element order must be reversed.
- How deep it goes
- Defines the specialized in-place operation and demonstrates its output, without discussing implementation internals.
- Examples
- Demonstrates reversing [1, 3, 5, 6, 7] to [7, 6, 5, 3, 1].
- What you can do after
- Apply the reverse method to change an existing list from forward order to backward order.
Read how The Quick Python Book, Fourth Edition explains reversing →
Related concepts
- persistent listproduces · A persistent list is an immutable ordered list whose updates produce new versions while preserving earlier versions, typically through structural sharing.
- listuses · A list is an ordered collection of elements arranged in a sequence.
- iteratorproduces · An iterator is an object or abstraction that provides successive values from a sequence or data source through a traversal protocol.
- slicingalternative to · Slicing selects or partitions a portion of an indexed sequence or multidimensional array, often along specified indices or dimensions.
- rangeuses · A language or API construct that represents or generates an ordered sequence or interval of values, with its bounds and any step interpreted according to that language or API.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


