Name

reversed()

Examples
numbers = [1, 2, 3]
reversed_numbers = reversed(numbers)
for num in reversed_numbers:
  print(num)
# Prints:
# 3
# 2
# 1

# Meanwhile, the original list has not been modified:
print(numbers) # Prints [1, 2, 3]
# The reversed() function returns an iterator by default. Use list() to
# convert the iterator to a list.
numbers = [1, 2, 3]
reversed_numbers = reversed(numbers)
reversed_list = list(reversed_numbers)
print(reversed_list) # Prints [3, 2, 1]
# reversed() can reverse any iterable, not just lists
word = "orderly"
reversed_word = reversed(word)
reversed_list = list(reversed_word)
print(reversed_list) # Prints ['y', 'l', 'r', 'e', 'd', 'r', 'o']
Description
Syntax
	reversed(x)
Parameters
x
Related .reverse()
.sort()
list()
sorted()
Updated on Wed Jan 18 17:32:21 2017.
Creative Commons License