Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python Write a program to reverse an array or string

# Iterative python program to reverse an array
 
# Function to reverse A[] from start to end
def reverseList(A, start, end):
    while start < end:
        A[start], A[end] = A[end], A[start]
        start += 1
        end -= 1
 
# Driver function to test above function
A = [1, 2, 3, 4, 5, 6]
print(A)
reverseList(A, 0, 5)
print("Reversed list is")
print(A)
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #python #Write #program #reverse #array #string
ADD COMMENT
Topic
Name
3+9 =