reverse and print array of ints in python

To reverse and print an array of integers in Python, you can use the built-in reverse() method and a for loop to print the reversed array.

Here's an example code snippet:

main.py
arr = [1, 2, 3, 4, 5]  # example array
arr.reverse()  # reverse the array in-place

# print the reversed array
for i in arr:
    print(i, end=" ")  # end=" " to print space-separated integers
192 chars
7 lines

Output:

main.py
5 4 3 2 1
10 chars
2 lines

In the above code, we first create an example array arr with integers from 1 to 5. Then we call the reverse() method on arr to reverse the elements in-place. Finally, we use a for loop to iterate over the reversed array and print each element separated by a space using the end=" " argument of the print() function.

gistlibby LogSnag