Question: 2: Python lists are extremely flexible tools for holding whatever data we want. Getting comfortable with them is an important first step in learning python.

2:

Python lists are extremely flexible tools for holding whatever data we want. Getting comfortable with them is an important first step in learning python. Following the instructions in the provided test file, write python functions to perform the following operations on lists.

lists_a: Swap the first and last elements of a list

lists_b:Shift all elements by one to the right and move the last element into the first position. For example, 1 4 9 16 25 would become 25 1 4 9 16. lists_c: Replace all even elements by 0 (all elements divisible by 2) lists_d:Replace each element except the first and last by the larger of its two neighbors

lists_e:Remove the middle element if the list length is odd, or the middle two elements if the length is even.

lists_f: Move all even elements to the front, otherwise preserving the order of the elements

lists_g: Return the second-largest element in the list lists_h: Return 1 if the list is currently sorted in increasing order, else -1 lists_i: Return 1 if the list contains two adjacent duplicate elements, else -1

lists_j: Return 1 if the list contains duplicate elements (need not be adjacent), else -1 Feel free to use any sample code given in class.

2: Python lists are extremely flexible tools for holding whatever data we

Python lists are extremely flexible tools for holding whatever data we want. Getting comfortable with them is an important first step in learning python. Following the instructions in the provided test file, write python functions to perform the following operations on lists. lists_a: Swap the first and last elements of a list lists b:Shift all elements by one to the right and move the last element into the first position. For example, 149 16 25 would become 25 1 4 9 16. mentul de commerce lists_c: Replace all even elements by 0 (all elements divisible by 2) lists_d:Replace each element except the first and last by the larger of its two neighbors lists_e:Remove the middle element if the list length is odd, or the middle two elements if the length is even. lists_f: Move all even elements to the front, otherwise preserving the order of the elements lists_g: Return the second-largest element in the list lists_h: Return 1 if the list is currently sorted in increasing order, else-1 lists_i: Return 1 if the list contains two adjacent duplicate elements, else - 1 lists_j: Return 1 if the list contains duplicate elements (need not be adjacent), else - 1 Feel free to use any sample code given in class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!