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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | def leftRotate(arr, d, n): for i in range(d): leftRotatebyOne(arr, n) #Function to left Rotate arr[] of size n by 1*/ def leftRotatebyOne(arr, n): temp = arr[0] for i in range(n-1): arr[i] = arr[i+1] arr[n-1] = temp # utility function to print an array */ def printArray(arr,size): 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) printArray(arr, 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.