Created
November 2, 2019 15:59
-
-
Save officialcjunior/213d9a2a2b9fbe8b4dedc725460f6bf0 to your computer and use it in GitHub Desktop.
This is a python program which right-rotates and left-rotates a list n times.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def leftrotate(a,n): | |
for i in range (n): | |
first=a[0] | |
for i in range (0,len(a)-1): | |
a[i]=a[i+1] | |
a.pop() | |
a.append(first) | |
print(a) | |
def rightrotate(a,n): | |
for i in range (n): | |
last=a[-1] | |
for i in range (len(a)-1,0,-1): | |
a[i]=a[i-1] | |
a[0]=last | |
print(a) | |
a=[int(i) for i in input("Enter the list elements (Space seperated) \n").split()] | |
n=int(input("Enter the number of times you want to rotate the list \n")) | |
rightrotate(a,n) | |
leftrotate(a,n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment