How to reverse a list in place

PHOTO EMBED

Tue Jun 18 2024 16:47:43 GMT+0000 (Coordinated Universal Time)

Saved by @pynerds #python

 
nums = [1, 2, 3, 4, 5]
print('before: ')
print(nums)

#call the reverse method()
nums.reverse()

print("after: ")
print(nums)
 
content_copyCOPY

https://www.pynerds.com/reverse-a-list-in-python/