Today we are going to share a python program for array rotation. If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share a python program for array rotation.
To increase your Python knowledge, practice all Python programs, here is a collection of 100+ Python problems with solutions.
Copy the below python program and execute it with the help of python compiler.
def leftRotate(arr, d, n):
for i in range(d):
#Function to left Rotate arr of size n by 1*/
def leftRotatebyOne(arr, n):
temp = arr
for i in range(n-1):
arr[i] = arr[i+1]
arr[n-1] = temp
# utility function to print an array */
for i in range(size):
print ("%d"% arr[i],end=" ")
# Driver program to test above functions */
arr = [1, 2, 3, 4, 5, 6, 7]
leftRotate(arr, 2, 7)
3 4 5 6 7 1 2
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.