Startup and Tech
Sunday 12 July 2020
Python Program to Rotate Array elements
Program
l = [5,8,10,12,15] left = 0 right = len(l)-1 def reveresef(l,left,right): #This function reverse the list elements while (left < right): l[left], l[right] = l[right], l[left] left += 1 right -= 1 d = int(input("How many numbers you want to shift: ")) if(d<=len(l)): reveresef(l, 0, d - 1) reveresef(l, d, right) reveresef(l, 0, right) print(l) else: print("enter d less than or equals to %d : "%len(l))
Output
How many numbers you want to shift: 3 [12, 15, 5, 8, 10]
Reverse Array In Python using algorithm
https://www.techrcoding.com/2020/07/reverse-array.html
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment