Python Program to Split the array and add the first part to the end

 In this blog, I'm going to tell how to Split the array and add the first part to the end using Python.





Example :

Input: arr[] = {1,2,3,4,5,6,7,8}

              k = 2

Output : arr[] = {3,4,5,6,7,8,1,2}

Explanation : Split from index 2 and first part {1, 2} add to the end .



def splitArr(arr, n, k): 
    for i in range(0, k): 
        x = arr[0]
        for j in range(0, n-1):
            arr[j] = arr[j + 1]
          
        arr[n-1] = x
          
  
# main
arr = [1,2,3,4,5,6,7,8]
n = len(arr)
position = 2
  
splitArr(arr, n, position)
  
for i in range(0, n): 
    print(arr[i], end = ' ')

Post a Comment

Previous Post Next Post
Best Programming Books

Facebook

AJ Facebook
Checkout Our Facebook Page
AJ Blogs
Checkout Our Instagram Page