Fewpal
0 votes
657 views
in Computer by (45.7k points)
closed by

Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is a numeric value by which all elements of the list are shifted to left. 

Sample Input Data of the list 

Arr= [ 10,20,30,40,12,11], n=2 

Output 

Arr = [30,40,12,11,10,20]

1 Answer

+1 vote
by (48.9k points)
selected by
 
Best answer

def LShift(Arr,n): 

L=len(Arr) 

for x in range(0,n): 

y=Arr[0] 

for i in range(0,L-1): 

Arr[i]=Arr[i+1] 

Arr[L-1]=y 

print(Arr) 

Note : Using of any correct code giving the same result is also accepted.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...