Reversed Iteration in Python
Level 373 keystrokes
This iterates over a list in reverse order. The reversed() function returns an iterator that goes backwards.
Python code
# Create a list of numbers1nums = [1, 2, 3, 4, 5]# reversed() returns an iterator in reverse order# end=" " prints space instead of newline2for n in reversed(nums):3 print(n, end=" ")# Print newline at the end4print()Output
5 4 3 2 1
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
,× 5(× 3)× 3"× 2=× 2:× 1[× 1]× 1