Skip to Main Content
Blog

Reverse an Array in-Place in Python

Reverse an Array in-Place in Python

def main():
	"""
	Reverses a list in-place and prints the reversed list.
	"""

	# Read a list from the user
	array = list(map(int, input("Enter list: ").split(",")))

	# Reverse the list in-place
	array.reverse()

	# Print the result
	print(array)


if __name__ == "__main__":
	main()