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]
Answers
Question:
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]
Solution:
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)
LearnMore on Brainly.in:
A binary file “STUDENT.DAT” has structure (admission_number, Name,
Percentage). Write a function countrec() in Python that would read contents
of the file “STUDENT.DAT” and display the details of those students whose
percentage is above 75. Also display number of students scoring above 75%.
https://brainly.in/question/25989972
Here's a function in Python that performs a left shift operation on a given list by a given number of positions:
def LShift(Arr, n):
for i in range(n):
Arr.append(Arr.pop(0))
return Arr
Here's how it works:
- Arr is the list that we want to shift to the left, and n is the number of positions by which we want to shift it.
- We use a for loop to iterate n times, since we want to shift the list by n positions.
- Inside the loop, we use the pop method to remove the first element of the list (which will be shifted to the end of the list), and then use the append method to add it to the end of the list.
- After the loop is finished, the shifted list is returned.
- Note that this function modifies the input list in place, so if you don't want to modify the original list, you should make a copy of it before passing it to the function.
To learn more about Python from the given link.
https://brainly.in/question/16086632
#SPJ6