reversed

Full name
reversed
Library
Built-in
Syntax

reversed(seq)

Description

The reversed function returns an iterator made up of the values of the object included as an argument after reversing their order.

Parameters
  • seq: Sequence to reverse.
Result

The reversed function returns an iterator.

Examples

If we start from a list:

a = [1, 2, 3, 4]

...we can create an iterator that returns the list values in reverse order with the following code:

r = reversed(a)
r

If we want to visualize the values we can convert the result into a list:

list(r)

[4, 3, 2, 1]

Submitted by admin on Sun, 01/17/2021 - 15:38