Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. (Lists) Write the function swap(L,i,j) that receives a list L and integers i and j and swaps the items at positions i and j
1. (Lists) Write the function swap(L,i,j) that receives a list L and integers i and j and swaps the items at positions i and j in L. 2. (Arrays) Write the function reverse 1D(A) that receives a 2D array A and returns a 1D array containing the elements of A in reverse order. For example, if A=np.array([[2,5,3],[0,8,1]]), your function should return the 1D array [1 8 0 3. (Sets) Write the function first_repeat (L) that receives a list L and returns the first repeated item in L. For example, first_repeat ([4,7,1,3,9,8,7,1,3,9]) should return 7 . If L has no repeated characters, your function should return None. Your function must run in O(n). 4. (Dictionaries) Write the function first_k_letters (W,k) that receives a list of words W and an integer k and returns a dictionary D, where D[w] contains the words in W that start with the k-letter string w. For example, first_k_letters (W,3) would return a dictionary D where D ['dat'] is ['data', 'date', 'database']. 5. (Lists) Write the function interleave(L1,L2) that receives two lists of the same length L1 and L2 and returns a list containing [L1[0],L2[0],L1[1],L2[1],L1[2],L2[2],]. 6. (Arrays) Write the function sum_corners(A) that receives a 2D array A and returns the sum of the items in the four corners of A. Assume A has at least two rows and two columns. 7. (Sets) Write the function appears_in_1(L1,L2) that receives two lists of integers L1 and L2 and returns a set containing the elements that appear in L1 or in L2 but not in both. 8. (Dictionaries) Write the function occurrences (S,n) that receives a string S and an integer n and builds and returns a dictionary containing the number of times each substring of S of length n appears in S
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started