16.5. Reversing a List¶
We can use the looping ability of computers, plus the indexing ability, to manipulate lists in interesting and even surprising ways. In the below program, we use an accumulator, which is something that accumulates values. We start with the accumulator
soFar set to an empty list – a list with nothing in it. As the program executes, it appends items from the
source list into the
] around the value in the
source at the current value of
index. This is needed because you can only concatenate two lists together. Try removing the
]. What error do you get?
Discuss topics in this section with classmates.
You have attempted of activities on this page