This function, applied to a sequence , returns an iterator that generates
the elements of S
in reverse order (see Section 24.2, “Iterators: Values that can produce a sequence of
values”).
S
>>> L=[22,44,88] >>> backL = reversed(L) >>> for i in backL: ... print i, ... 88 44 22
The allowable values for include all the types described in Section 8, “Sequence types”. It also works for any
class provided one of these two conditions is met:
S
The method described in Section 26.3.20, “__reversed__(): Implement the reversed() function”.
If the class has no .__reversed__() method,
reversed() will still work provided that
instances act like a sequence; that is, the class has a
.__len__() method and a .__getitem__() method.