Python Left Rotation Operation || Array || Python


In this we are going to see a basic program to perform left rotation operation on each element of array in Python Programming Language.



def rotateLeft(d, arr):
    newArr = []
    for i in range(d, len(arr)):
        newArr.append(arr[i])
        i = i+1
    i = 0
    for i in range(0, d):
        newArr.append(arr[i])
    return newArr

def main():
    d = int(input("Enter the number of left rotations: "))
    arr = list(map(int, input("Enter array: ").split()))
    print(rotateLeft(d, arr))

main()

# Coded by Shreya Idate


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post