Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
275k views
in Computer by (46.2k 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]

by (10 points)
+1
def Lshift(Arr,n):
    print(Arr[n:]+Arr[:n])

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


NOTE: You can give any value of n as u wish. Any other program is also valid

1 Answer

+2 votes
by (49.2k 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

...