Reverse List in Python

Level 249 keystrokes

This reverses the list in place. The reverse() method modifies the original list, reversing the order of elements.

Python code

# Create a list of numbers
1nums = [1, 2, 3, 4, 5]
# reverse() reverses the list in place (modifies original)
# After this, nums becomes [5, 4, 3, 2, 1]
2nums.reverse()
# Print the reversed list
3print(nums)

Output

[5, 4, 3, 2, 1]
Practice typing this code

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.

  • ,× 4
  • (× 2
  • )× 2
  • .× 1
  • [× 1
  • ]× 1
  • =× 1

More Python examples at level 2

← Python typing practice