Answers for "rotate and assign part of array left cyclically"

2

cyclically rotate an array by one

def rotate( arr, n):
    a[0],a[1:]=a[-1],a[:n-1]
    
#Driver Code    
a=[-1,2,3,7,5]
rotate(a,len(a))
print(a)
#Output: [5, -1, 2, 3, 7]
Posted by: Guest on September-10-2021

Python Answers by Framework

Browse Popular Code Answers by Language