concept reversed() in category python

appears as: reversed()
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 list.sort() and list.reverse()methods are easily confused with the sorted() and reversed()functions. The sorted()function accepts a list as an argument and returns a new list:

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:

Here the reversed() iterator will be added to the end of lines, such that it would have three elements rather than the desired five:

>>> lines.append(reversed(gifts[:day]))
>>> lines
['On the third day of Christmas,',
 'My true love gave to me,',
 <list_reverseiterator object at 0x105bc8588>]

Maybe you’re thinking you could coerce reversed() with the list() function? Thinking you are, young Jedi, but, alas, that will still add a new list to the end: