Reversing a copy of a list
Once in a while, we need to reverse the order of the items in a list
collection. Some algorithms, for example, produce results in a reverse order. We'll look at the way numbers converted into a specific base are often generated from least-significant to most-significant digit. We generally want to display the values with the most-significant digit first. This leads to a need to reverse the sequence of digits in a list.
We have three ways to reverse a list. First, there's the reverse()
method. We can also use the reversed()
function, as well as a slice that visits items in reverse order.
Getting ready
Let's say we're doing a conversion among number bases. We'll look at how a number is represented in a base, and how we can compute that representation from a number.
Any value, v, can be defined as a polynomial function of the various digits, dn, in a given base, b:
A rational number has a finite...