concept reversed ( ) function in category python

appears as: The reversed() function, reversed() function
Tiny Python Projects: Learn coding and testing with puzzles and games

This is an excerpt from Manning's book Tiny Python Projects: Learn coding and testing with puzzles and games.

The reversed() function works a bit differently:

>>> reversed(items)
<list_reverseiterator object at 0x10e012ef0>

I bet you were expecting to see a new list with the items in reverse. This is an example of a lazy function in Python. The process of reversing a list might take a while, so Python is showing that it has generated an iterator object that will provide the reversed list when we actually need the elements.

We talked in chapter 3 about how you can reverse a list, either with the list.reverse() method or the reversed() function. We also used these ideas in chapter 11 to get the bottles of beer off the wall, so this code should not be unfamiliar: