rlist = list(reversed(slist))
Then repeat as often as you want. This trick is applied more generally; whenever you need to iterate over an iterator many times, turn it into a list. Here is a snippet of code that I copy to different projects for this purpose:
def tosequence(it):
"""Turn iterable into a sequence, avoiding a copy if possible."""
if not isinstance(it, collections.Sequence):
it = list(it)
return it
( Sequence- An abstract type of lists, tuples, and many custom objects like lists.)
source
share