#Example, if N=2, given the input array [1, 2, 3, 4, 5, 6].the function should return [5, 6, 1, 2, 3, 4]
def copyDigit(list,index,item):
"""
Copy the item to the indexed location in the given list
"""
list[index] = item
return list
def rotateList(noListToRorate,timesRotate):
"""
Rotate List to right
"""
print "Function received {0},{1}".format(noListToRorate,timesRotate)
for rotate in range(N):
lastItemInList = noListToRorate[-1]
for i in range(len(noListToRorate)-2,-1,-1):
itemToShift = noListToRorate[i]
noListToRorate = copyDigit(noListToRorate,i+1,itemToShift)
noListToRorate[0] = lastItemInList
print "Rotate once: {0}".format(noListToRorate)
return noListToRorate
if __name__ == '__main__':
"""
This program will rorate right the given list N no of times
"""
arrayList = [1,2,3,4,5,6]
N = 2
print "Rotate an array: " ,(arrayList), "No of times: ", N
finalList = rotateList(arrayList,N)
print "Rotated List: ", finalList